diff --git a/packages/super-editor/src/core/super-converter/exporter.js b/packages/super-editor/src/core/super-converter/exporter.js index cf79153ab2..56920b9b97 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, @@ -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..c4435ee2be 100644 --- a/packages/super-editor/src/core/super-converter/helpers.js +++ b/packages/super-editor/src/core/super-converter/helpers.js @@ -84,6 +84,22 @@ function ptToTwips(pt) { return pt * 20; } +/** + * 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 = { + 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 +246,5 @@ export { getLineHeightValueString, deobfuscateFont, hasSomeParentWithClass, + getTextIndentExportValue, };