Commit e989b764 authored by nelliemckesson's avatar nelliemckesson

restrict hyphens to word chars

parent db26db68
......@@ -68,7 +68,7 @@
<p>CSS IS AWE&shy;SOME!</p>
<p>
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps overrrr—the lazy dog.
</p>
</body>
......
......@@ -28,6 +28,12 @@ describe('css is awesome', async () => {
expect(text).toContain('\u2010');
})
xit('page 5 should NOT have a hyphen', async () => {
let text = await page.$eval("[data-page-number='5']", (r) => r.textContent);
expect(text).not.toContain('\u2010');
})
if (!DEBUG) {
xit('should create a pdf', async () => {
......
......@@ -343,6 +343,7 @@ class Layout {
if (overflow) {
breakToken = this.createBreakToken(overflow, rendered, source);
let breakLetter = breakToken["node"].textContent.charAt(breakToken["offset"]);
let breakHooks = this.hooks.onBreakToken.triggerSync(breakToken, overflow, rendered, this);
breakHooks.forEach((newToken) => {
......@@ -353,7 +354,7 @@ class Layout {
if (breakToken && breakToken.node && extract) {
this.removeOverflow(overflow);
this.removeOverflow(overflow, breakLetter);
}
}
......@@ -568,22 +569,22 @@ class Layout {
return offset;
}
removeOverflow(overflow) {
removeOverflow(overflow, breakLetter) {
let {startContainer} = overflow;
let extracted = overflow.extractContents();
this.hyphenateAtBreak(startContainer);
this.hyphenateAtBreak(startContainer, breakLetter);
return extracted;
}
hyphenateAtBreak(startContainer) {
hyphenateAtBreak(startContainer, breakLetter) {
if (isText(startContainer)) {
let startText = startContainer.textContent;
let prevLetter = startText[startText.length-1];
// Add a hyphen if previous character is a letter or soft hyphen
if (/^\w|\u00AD$/.test(prevLetter)) {
if (/^\w|\u00AD$/.test(prevLetter) && /^\w|\u00AD$/.test(breakLetter)) {
startContainer.parentNode.classList.add("pagedjs_hyphen");
startContainer.textContent += "\u2011";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment