From 63262bbc4b80ce5d119b4b98e1eb9035c8766ecc Mon Sep 17 00:00:00 2001 From: Ibrahim El-bastawisi Date: Thu, 16 Jan 2025 15:19:15 +0200 Subject: [PATCH] docx quote indent fixes --- src/editor/utils/docx/index.ts | 8 +++----- src/editor/utils/docx/text.ts | 8 ++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/editor/utils/docx/index.ts b/src/editor/utils/docx/index.ts index 4e6b289..76f4e30 100644 --- a/src/editor/utils/docx/index.ts +++ b/src/editor/utils/docx/index.ts @@ -100,13 +100,12 @@ function $mapNodeToDocx(node: LexicalNode): FileChild | ParagraphChild | Paragra style: 'Quote', alignment, indent: { - // start: 15 * 15 * (indent + 1), - hanging: 14 * 15 + start: 24 * 15 * (indent + 1), }, bidirectional: dir === 'rtl', border: { - left: dir === 'rtl' ? undefined : { size: 30, color: '#ced0d4', style: 'single', space: 8 }, - right: dir === 'rtl' ? { size: 30, color: '#ced0d4', style: 'single', space: 8 } : undefined, + left: dir === 'rtl' ? undefined : { size: 30, color: '#ced0d4', style: 'single', space: 12 + 24 * 0.75 * indent }, + right: dir === 'rtl' ? { size: 30, color: '#ced0d4', style: 'single', space: 12 + 24 * 0.75 * indent } : undefined, top: { space: 4, style: 'none' }, bottom: { space: 2, style: 'none' }, }, @@ -177,7 +176,6 @@ export async function $generateDocxBlob(): Promise { run: { color: '#65676b', }, paragraph: { spacing: { after: 10 * 15 }, - indent: { left: 30 * 15 }, }, }, ], diff --git a/src/editor/utils/docx/text.ts b/src/editor/utils/docx/text.ts index 42af7a6..6cfd844 100644 --- a/src/editor/utils/docx/text.ts +++ b/src/editor/utils/docx/text.ts @@ -5,24 +5,24 @@ import { ElementNode, TextNode } from "lexical"; export function $convertTextNode(node: TextNode) { const textContent = node.getTextContent(); - const isHeadingText = !!($findMatchingParent(node, $isHeadingNode)); const nearestListItem = $findMatchingParent(node, $isListItemNode); - const isCheckedText = !!(nearestListItem?.getChecked()); + const isCheckedText = nearestListItem?.getChecked(); const isLinkText = $findMatchingParent(node, $isLinkNode); const nearestTableCell = $findMatchingParent(node, $isTableCellNode); const tableCellColor = nearestTableCell ? $getNodeStyleValueForProperty(nearestTableCell, 'color').replace('inherit', '') : undefined; const fontsizeInPx = parseInt($getNodeStyleValueForProperty(node, 'font-size')); + const color = $getNodeStyleValueForProperty(node, 'color').replace('inherit', '') || tableCellColor; const backgroundColor = $getNodeStyleValueForProperty(node, 'background-color').replace('inherit', '') || undefined; const parent = node.getParent(); const direction = parent?.getDirection(); const textRun = new TextRun({ text: textContent, - bold: node.hasFormat('bold') || isHeadingText, + bold: node.hasFormat('bold') || undefined, italics: node.hasFormat('italic'), strike: node.hasFormat('strikethrough') || isCheckedText, underline: node.hasFormat('underline') ? { type: "single" } : undefined, - color: $getNodeStyleValueForProperty(node, 'color') || tableCellColor, + color: color, highlight: node.hasFormat('highlight') ? 'yellow' : undefined, subScript: node.hasFormat('subscript'), superScript: node.hasFormat('superscript'),