Skip to content

Commit 644a94e

Browse files
committed
fix(text indent): parse unit on export
1 parent a44ad1c commit 644a94e

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

packages/super-editor/src/core/super-converter/exporter.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EditorState } from 'prosemirror-state';
44
import { SuperConverter } from './SuperConverter.js';
55
import {
66
emuToPixels,
7+
getTextIndentExportValue,
78
inchesToTwips,
89
linesToTwips,
910
pixelsToEightPoints,
@@ -233,7 +234,7 @@ function generateParagraphProperties(node) {
233234
const { styleId } = attrs;
234235
if (styleId) pPrElements.push({ name: 'w:pStyle', attributes: { 'w:val': styleId } });
235236

236-
const { spacing, indent, textAlign, textIndent, lineHeight, marksAttrs, keepLines, keepNext, dropcap } = attrs;
237+
let { spacing, indent, textAlign, textIndent, lineHeight, marksAttrs, keepLines, keepNext, dropcap } = attrs;
237238
if (spacing) {
238239
const { lineSpaceBefore, lineSpaceAfter, lineRule } = spacing;
239240

@@ -280,7 +281,7 @@ function generateParagraphProperties(node) {
280281
if (hanging || hanging === 0) attributes['w:hanging'] = pixelsToTwips(hanging);
281282

282283
if (textIndent && !attributes['w:left']) {
283-
attributes['w:left'] = inchesToTwips(textIndent);
284+
attributes['w:left'] = getTextIndentExportValue(textIndent);
284285
}
285286

286287
const indentElement = {
@@ -292,7 +293,7 @@ function generateParagraphProperties(node) {
292293
const indentElement = {
293294
name: 'w:ind',
294295
attributes: {
295-
'w:left': inchesToTwips(textIndent),
296+
'w:left': getTextIndentExportValue(textIndent),
296297
},
297298
};
298299
pPrElements.push(indentElement);

packages/super-editor/src/core/super-converter/helpers.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ function ptToTwips(pt) {
8484
return pt * 20;
8585
}
8686

87+
// There is an indent value in Whalar template which appears with pt unit and cause issues on export
88+
const getTextIndentExportValue = (indent) => {
89+
const [value, unit] = parseSizeUnit(indent);
90+
const functionsMap = {
91+
pt: ptToTwips,
92+
in: inchesToTwips,
93+
};
94+
95+
const exportValue = functionsMap[unit] ? functionsMap[unit](value) : pixelsToTwips(value);
96+
return exportValue;
97+
};
98+
8799
const getArrayBufferFromUrl = async (input, isHeadless) => {
88100
// Check if it's a full URL or blob/file/data URI
89101
const isLikelyUrl = /^https?:|^blob:|^file:|^data:/i.test(input);
@@ -230,4 +242,5 @@ export {
230242
getLineHeightValueString,
231243
deobfuscateFont,
232244
hasSomeParentWithClass,
245+
getTextIndentExportValue,
233246
};

0 commit comments

Comments
 (0)