Skip to content

Commit 853d228

Browse files
fix(text indent): parse unit on export (#782)
* fix(text indent): parse unit on export * fix: change let to const * chore: add jdsoc to new indent export function --------- Co-authored-by: Nick Bernal <nick@harbourshare.com>
1 parent 2786ffc commit 853d228

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SuperConverter } from './SuperConverter.js';
55
import { toKebabCase } from '@harbour-enterprises/common';
66
import {
77
emuToPixels,
8+
getTextIndentExportValue,
89
inchesToTwips,
910
linesToTwips,
1011
pixelsToEightPoints,
@@ -281,7 +282,7 @@ function generateParagraphProperties(node) {
281282
if (hanging || hanging === 0) attributes['w:hanging'] = pixelsToTwips(hanging);
282283

283284
if (textIndent && !attributes['w:left']) {
284-
attributes['w:left'] = inchesToTwips(textIndent);
285+
attributes['w:left'] = getTextIndentExportValue(textIndent);
285286
}
286287

287288
const indentElement = {
@@ -293,7 +294,7 @@ function generateParagraphProperties(node) {
293294
const indentElement = {
294295
name: 'w:ind',
295296
attributes: {
296-
'w:left': inchesToTwips(textIndent),
297+
'w:left': getTextIndentExportValue(textIndent),
297298
},
298299
};
299300
pPrElements.push(indentElement);

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

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

87+
/**
88+
* Get the export value for text indent
89+
* @param {string|number} indent - The text indent value to export
90+
* @returns {number} - The export value in twips
91+
*/
92+
const getTextIndentExportValue = (indent) => {
93+
const [value, unit] = parseSizeUnit(indent);
94+
const functionsMap = {
95+
pt: ptToTwips,
96+
in: inchesToTwips,
97+
};
98+
99+
const exportValue = functionsMap[unit] ? functionsMap[unit](value) : pixelsToTwips(value);
100+
return exportValue;
101+
};
102+
87103
const getArrayBufferFromUrl = async (input, isHeadless) => {
88104
// Check if it's a full URL or blob/file/data URI
89105
const isLikelyUrl = /^https?:|^blob:|^file:|^data:/i.test(input);
@@ -230,4 +246,5 @@ export {
230246
getLineHeightValueString,
231247
deobfuscateFont,
232248
hasSomeParentWithClass,
249+
getTextIndentExportValue,
233250
};

0 commit comments

Comments
 (0)