Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pdf export decoration formatting #2826

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,49 @@ describe(`HtmlToPdfService`, () => {
{ text: [{ text: `Underlined`, decoration: `underline` }], decoration: `underline` }
]);
});

it(`struck span`, () => {
const result = service.convertHtml({
htmlText: `<span style="text-decoration: line-through">Struck</span>`
});
expect(result).toEqual(<Content[]>[
{ text: [{ text: `Struck`, decoration: `lineThrough` }], decoration: `lineThrough` }
]);
});

it(`nested underlined and struck spans`, () => {
const result = service.convertHtml({
htmlText: `<span style="text-decoration: line-through"><span style="text-decoration: underline">Both</span></span>`
});
expect(result).toEqual(<Content[]>(<unknown>[
{
text: [
{
text: [{ text: `Both`, decoration: [`underline`, `lineThrough`] }],
decoration: [`underline`, `lineThrough`]
}
],
decoration: `lineThrough`
}
]));
});

it(`nested underlined and struck spans 2`, () => {
const result = service.convertHtml({
htmlText: `<span style="text-decoration: underline"><span style="text-decoration: line-through">Both</span></span>`
});
expect(result).toEqual(<Content[]>(<unknown>[
{
text: [
{
text: [{ text: `Both`, decoration: [`lineThrough`, `underline`] }],
decoration: [`lineThrough`, `underline`]
}
],
decoration: `underline`
}
]));
});
});

describe(`convert format tags`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ export class HtmlToPdfService {
case `text-decoration`: {
switch (value) {
case `underline`: {
styleObject.decoration = value;
styleObject.decoration = (styleObject.decoration ?? []).concat(value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is currently not officially supported by pdfmake I opened PRs in pdfmake doc and DefinetlyTyped.

break;
}
case `line-through`: {
styleObject.decoration = `lineThrough`;
styleObject.decoration = (styleObject.decoration ?? []).concat(`lineThrough`);
break;
}
}
Expand All @@ -513,6 +513,9 @@ export class HtmlToPdfService {
}
}
}
if (Array.isArray(styleObject.decoration) && styleObject.decoration.length === 1) {
styleObject.decoration = styleObject.decoration[0];
}
return styleObject;
}

Expand Down