From 644a94e9fc01805f048b2fe352132ad482131244 Mon Sep 17 00:00:00 2001 From: VladaHarbour Date: Mon, 18 Aug 2025 17:01:17 +0300 Subject: [PATCH 1/3] fix(text indent): parse unit on export --- .../src/core/super-converter/exporter.js | 7 ++++--- .../src/core/super-converter/helpers.js | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/super-editor/src/core/super-converter/exporter.js b/packages/super-editor/src/core/super-converter/exporter.js index cf79153ab2..ea16d91577 100644 --- a/packages/super-editor/src/core/super-converter/exporter.js +++ b/packages/super-editor/src/core/super-converter/exporter.js @@ -4,6 +4,7 @@ import { EditorState } from 'prosemirror-state'; import { SuperConverter } from './SuperConverter.js'; import { emuToPixels, + getTextIndentExportValue, inchesToTwips, linesToTwips, pixelsToEightPoints, @@ -233,7 +234,7 @@ function generateParagraphProperties(node) { const { styleId } = attrs; if (styleId) pPrElements.push({ name: 'w:pStyle', attributes: { 'w:val': styleId } }); - const { spacing, indent, textAlign, textIndent, lineHeight, marksAttrs, keepLines, keepNext, dropcap } = attrs; + let { spacing, indent, textAlign, textIndent, lineHeight, marksAttrs, keepLines, keepNext, dropcap } = attrs; if (spacing) { const { lineSpaceBefore, lineSpaceAfter, lineRule } = spacing; @@ -280,7 +281,7 @@ function generateParagraphProperties(node) { if (hanging || hanging === 0) attributes['w:hanging'] = pixelsToTwips(hanging); if (textIndent && !attributes['w:left']) { - attributes['w:left'] = inchesToTwips(textIndent); + attributes['w:left'] = getTextIndentExportValue(textIndent); } const indentElement = { @@ -292,7 +293,7 @@ function generateParagraphProperties(node) { const indentElement = { name: 'w:ind', attributes: { - 'w:left': inchesToTwips(textIndent), + 'w:left': getTextIndentExportValue(textIndent), }, }; pPrElements.push(indentElement); diff --git a/packages/super-editor/src/core/super-converter/helpers.js b/packages/super-editor/src/core/super-converter/helpers.js index 83948a25fd..37be7f6ff4 100644 --- a/packages/super-editor/src/core/super-converter/helpers.js +++ b/packages/super-editor/src/core/super-converter/helpers.js @@ -84,6 +84,18 @@ function ptToTwips(pt) { return pt * 20; } +// There is an indent value in Whalar template which appears with pt unit and cause issues on export +const getTextIndentExportValue = (indent) => { + const [value, unit] = parseSizeUnit(indent); + const functionsMap = { + pt: ptToTwips, + in: inchesToTwips, + }; + + const exportValue = functionsMap[unit] ? functionsMap[unit](value) : pixelsToTwips(value); + return exportValue; +}; + const getArrayBufferFromUrl = async (input, isHeadless) => { // Check if it's a full URL or blob/file/data URI const isLikelyUrl = /^https?:|^blob:|^file:|^data:/i.test(input); @@ -230,4 +242,5 @@ export { getLineHeightValueString, deobfuscateFont, hasSomeParentWithClass, + getTextIndentExportValue, }; From ba630ae82d7575074e8ccc3670042377025af26d Mon Sep 17 00:00:00 2001 From: VladaHarbour Date: Mon, 18 Aug 2025 17:02:27 +0300 Subject: [PATCH 2/3] fix: change let to const --- packages/super-editor/src/core/super-converter/exporter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/super-editor/src/core/super-converter/exporter.js b/packages/super-editor/src/core/super-converter/exporter.js index ea16d91577..56920b9b97 100644 --- a/packages/super-editor/src/core/super-converter/exporter.js +++ b/packages/super-editor/src/core/super-converter/exporter.js @@ -234,7 +234,7 @@ function generateParagraphProperties(node) { const { styleId } = attrs; if (styleId) pPrElements.push({ name: 'w:pStyle', attributes: { 'w:val': styleId } }); - let { spacing, indent, textAlign, textIndent, lineHeight, marksAttrs, keepLines, keepNext, dropcap } = attrs; + const { spacing, indent, textAlign, textIndent, lineHeight, marksAttrs, keepLines, keepNext, dropcap } = attrs; if (spacing) { const { lineSpaceBefore, lineSpaceAfter, lineRule } = spacing; From 208552c2d75b001503fa9ef0898373059e022dc2 Mon Sep 17 00:00:00 2001 From: Nick Bernal Date: Mon, 18 Aug 2025 10:26:04 -0400 Subject: [PATCH 3/3] chore: add jdsoc to new indent export function --- packages/super-editor/src/core/super-converter/helpers.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/super-editor/src/core/super-converter/helpers.js b/packages/super-editor/src/core/super-converter/helpers.js index 37be7f6ff4..c4435ee2be 100644 --- a/packages/super-editor/src/core/super-converter/helpers.js +++ b/packages/super-editor/src/core/super-converter/helpers.js @@ -84,7 +84,11 @@ function ptToTwips(pt) { return pt * 20; } -// There is an indent value in Whalar template which appears with pt unit and cause issues on export +/** + * Get the export value for text indent + * @param {string|number} indent - The text indent value to export + * @returns {number} - The export value in twips + */ const getTextIndentExportValue = (indent) => { const [value, unit] = parseSizeUnit(indent); const functionsMap = {