Skip to content

Commit

Permalink
Fix pdf export decoration formatting (#2826)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisa-beerboom authored Sep 26, 2023
1 parent 3800bde commit d484bf5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
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);
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

0 comments on commit d484bf5

Please sign in to comment.