@printedjs/plugin-hyphenation
v0.2.3
Published
CSS hyphenation and word-break preservation plugin for Printedjs.
Readme
@printedjs/plugin-hyphenation
CSS hyphenation and word-break preservation plugin for Printedjs.
Provides cross-browser hyphenation normalization and text measurement preservation across paginated boundaries.
Features
- Vendor Prefix Expansion — Normalizes standard CSS
hyphens: autoto include-webkit-and-ms-vendor prefixes. - Soft Hyphen Protection — Traverses DOM text nodes to identify and preserve soft hyphens (
\u00AD/­) during page measurement and node slicing. - Accurate Word Boundary Wrapping — Prevents unexpected line-wrapping artifacts at page breaks.
Installation
pnpm add @printedjs/plugin-hyphenation @printedjs/coreUsage
import { createRenderer } from "@printedjs/browser";
import { hyphenationPlugin } from "@printedjs/plugin-hyphenation";
const renderer = createRenderer({
target: document.querySelector("#preview")!,
plugins: [hyphenationPlugin()],
});
await renderer.render({
content: {
html: `
<style>
p {
hyphens: auto;
text-align: justify;
}
</style>
<p>Super­cali­fragi­listic­expi­ali­docious</p>
`,
},
});