Preserve QWord strikethrough formatting

This commit is contained in:
Курнат Андрей
2026-06-01 07:14:24 +03:00
parent 5a968dea72
commit ea26f5c55d
5 changed files with 63 additions and 3 deletions
+12 -1
View File
@@ -10,6 +10,7 @@ export interface WordInlineRun {
bold?: boolean;
italics?: boolean;
underline?: boolean;
strike?: boolean;
href?: string;
color?: string;
highlightColor?: string;
@@ -353,6 +354,9 @@ function wordInlineRunToTextRunOption(run: WordInlineRun) {
if (run.underline) {
options.underline = {};
}
if (run.strike) {
options.strike = true;
}
if (run.color) {
options.color = run.color;
}
@@ -681,7 +685,8 @@ function docxRunToHtml(run: unknown) {
const highlightColor = docxRunHighlightColor(properties);
const fontSize = docxRunFontSize(properties);
const fontFamily = docxRunFontFamily(properties);
const hasInlineColorOrHighlight = Boolean(color || highlightColor || fontSize || fontFamily);
const hasStrike = hasDocxBoolean(properties, "w:strike") || hasDocxBoolean(properties, "w:dstrike");
const hasInlineColorOrHighlight = Boolean(color || highlightColor || fontSize || fontFamily || hasStrike);
let html = escapeHtml(text);
if (!text) {
@@ -697,6 +702,9 @@ function docxRunToHtml(run: unknown) {
if (hasDocxBoolean(properties, "w:u")) {
html = `<u>${html}</u>`;
}
if (hasStrike) {
html = `<s>${html}</s>`;
}
const styles = [
color ? `color: #${color};` : "",
@@ -870,6 +878,7 @@ function formatForElement(element: Element, inherited: InlineFormat): InlineForm
bold: inherited.bold || tagName === "b" || tagName === "strong" || /font-weight\s*:\s*(bold|[6-9]00)\b/i.test(style),
italics: inherited.italics || tagName === "i" || tagName === "em" || /font-style\s*:\s*italic\b/i.test(style),
underline: inherited.underline || tagName === "u" || /text-decoration(?:-line)?\s*:[^;]*underline/i.test(style),
strike: inherited.strike || tagName === "s" || tagName === "strike" || tagName === "del" || /text-decoration(?:-line)?\s*:[^;]*line-through/i.test(style),
...(href ? { href } : {}),
...(color ? { color } : {}),
...(highlightColor ? { highlightColor } : {}),
@@ -910,6 +919,7 @@ function sameInlineFormat(first: InlineFormat, second: InlineFormat) {
Boolean(first.bold) === Boolean(second.bold) &&
Boolean(first.italics) === Boolean(second.italics) &&
Boolean(first.underline) === Boolean(second.underline) &&
Boolean(first.strike) === Boolean(second.strike) &&
(first.href ?? "") === (second.href ?? "") &&
(first.color ?? "") === (second.color ?? "") &&
(first.highlightColor ?? "") === (second.highlightColor ?? "") &&
@@ -923,6 +933,7 @@ function cleanInlineFormat(format: InlineFormat): InlineFormat {
...(format.bold ? { bold: true } : {}),
...(format.italics ? { italics: true } : {}),
...(format.underline ? { underline: true } : {}),
...(format.strike ? { strike: true } : {}),
...(format.href ? { href: format.href } : {}),
...(format.color ? { color: format.color } : {}),
...(format.highlightColor ? { highlightColor: format.highlightColor } : {}),