Skip to content

Commit 43146ce

Browse files
committed
fix paragraph text indentation
1 parent 32cd311 commit 43146ce

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function generateParagraphProperties(node) {
167167
const { styleId } = attrs;
168168
if (styleId) pPrElements.push({ name: 'w:pStyle', attributes: { 'w:val': styleId } });
169169

170-
const { spacing, indent, textAlign } = attrs;
170+
const { spacing, indent, textAlign, textIndent } = attrs;
171171
if (spacing) {
172172
const { lineSpaceBefore, lineSpaceAfter, line, lineRule } = spacing;
173173

@@ -185,19 +185,31 @@ function generateParagraphProperties(node) {
185185
};
186186
pPrElements.push(spacingElement);
187187
}
188-
188+
189189
if (indent) {
190190
const { left, right, firstLine } = indent;
191191
const attributes = {};
192192
if (left || left === 0) attributes['w:left'] = pixelsToTwips(left);
193193
if (right || right === 0) attributes['w:right'] = pixelsToTwips(right);
194194
if (firstLine || firstLine === 0) attributes['w:firstLine'] = pixelsToTwips(firstLine);
195195

196+
if (textIndent && !attributes['w:left']) {
197+
attributes['w:left'] = inchesToTwips(textIndent);
198+
}
199+
196200
const indentElement = {
197201
name: 'w:ind',
198202
attributes,
199203
};
200204
pPrElements.push(indentElement);
205+
} else if (textIndent) {
206+
const indentElement = {
207+
name: 'w:ind',
208+
attributes: {
209+
'w:left': inchesToTwips(textIndent),
210+
},
211+
};
212+
pPrElements.push(indentElement);
201213
}
202214

203215
if (textAlign) {

packages/super-editor/src/core/super-converter/v2/importer/markImporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function getFontFamilyValue(attributes, docx) {
167167

168168
function getIndentValue(attributes) {
169169
let value = attributes['w:left'];
170-
if (!value) value = attributes['w:firstLine'];
170+
if (!value) return null;
171171
return `${twipsToInches(value)}in`;
172172
}
173173

packages/super-editor/src/core/super-converter/v2/importer/paragraphNodeImporter.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ export const handleParagraphNode = (params) => {
6464
if (firstLine) schemaNode.attrs['indent'].firstLine = twipsToPixels(firstLine);
6565
}
6666

67-
const textIndentVal = left || firstLine || 0;
68-
schemaNode.attrs['textIndent'] = `${twipsToInches(textIndentVal)}in`;
67+
const textIndentValue = left || 0;
68+
69+
if (textIndentValue) {
70+
schemaNode.attrs['textIndent'] = `${twipsToInches(textIndentValue)}in`;
71+
}
6972
}
7073

7174
const justify = pPr?.elements?.find((el) => el.name === 'w:jc');

packages/super-editor/src/extensions/text-indent/text-indent.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { Extension } from '@core/index.js';
22
import { parseSizeUnit } from '@core/utilities/index.js';
33

4-
/**
5-
* Do we need a unit conversion system?
6-
*
7-
* For reference.
8-
* https://remirror.vercel.app/?path=/story/extensions-nodeformatting--basic
9-
* https://github.com/remirror/remirror/tree/HEAD/packages/remirror__extension-node-formatting
10-
*/
114
export const TextIndent = Extension.create({
125
name: 'textIndent',
136

@@ -32,7 +25,7 @@ export const TextIndent = Extension.create({
3225
renderDOM: (attrs) => {
3326
if (!attrs.textIndent) return {};
3427
let [value, unit] = parseSizeUnit(attrs.textIndent);
35-
if (Number.isNaN(value)) return {};
28+
if (Number.isNaN(value) || !value) return {};
3629
unit = unit ? unit : this.options.defaults.unit;
3730
return { style: `margin-left: ${value}${unit}` };
3831
},

0 commit comments

Comments
 (0)