Skip to content

Commit cba5771

Browse files
authored
Merge pull request #485 from Harbour-Enterprises/har-9432_list-spacing
HAR-9432 fix spacing for the list with styleID
2 parents 655a64f + fa70670 commit cba5771

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ function handleListNodes({
126126
// Get the properties of the node - this is where we will find depth level for the node
127127
// As well as many other list properties
128128
const { attributes, elements, marks = [] } = parseProperties(item, docx);
129+
130+
const matchedStyle = getStyleTagFromStyleId(styleId, docx) || {};
131+
const { marks: styleIdMarks } = parseProperties(matchedStyle, docx);
132+
129133
const textStyle = marks.find((mark) => mark.type === 'textStyle');
134+
const textStyleFromStyles = styleIdMarks?.find((mark) => mark.type === 'textStyle');
130135

131136
const {
132137
listType,
@@ -180,7 +185,7 @@ function handleListNodes({
180185
parNode = {
181186
...parNode,
182187
attrs: {
183-
textAlign: textStyle?.attrs.textAlign || null,
188+
textAlign: textStyle?.attrs.textAlign || textStyleFromStyles?.attrs.textAlign || null,
184189
rsidRDefault: attributes?.['w:rsidRDefault'] || null,
185190
},
186191
content: mergeTextNodes(parNode.content),
@@ -209,7 +214,11 @@ function handleListNodes({
209214

210215
// Process additional possible inline styles
211216
const pPr = item.elements.find((el) => el.name === 'w:pPr');
212-
const indent = pPr?.elements.find((el) => el.name === 'w:ind');
217+
let indent = pPr?.elements.find((el) => el.name === 'w:ind');
218+
const pPrFromStyles = matchedStyle?.elements?.find((style) => style.name === 'w:pPr');
219+
const stylesIndent = pPrFromStyles?.elements?.find((el) => el.name === 'w:ind');
220+
if (!indent) indent = stylesIndent;
221+
213222
if (indent) {
214223
const indentAttrs = {};
215224
if (indent.attributes['w:left'] !== undefined) indentAttrs.left = twipsToPixels(indent.attributes['w:left']);
@@ -240,7 +249,7 @@ function handleListNodes({
240249
nodeAttributes['numId'] = numId;
241250

242251
if (docx) {
243-
nodeAttributes['spacing'] = getParagraphSpacing(item, docx);
252+
nodeAttributes['spacing'] = getParagraphSpacing(item, docx, styleId);
244253
}
245254

246255
const newListItem = createListItem(schemaElements, nodeAttributes, []);
@@ -353,11 +362,14 @@ const getNumIdFromTag = (tag) => {
353362
*/
354363
function getStyleTagFromStyleId(styleId, docx) {
355364
const styles = docx['word/styles.xml'];
365+
if (!styles) {
366+
return {};
367+
}
356368
const styleEls = styles.elements;
357369
const wStyles = styleEls.find((el) => el.name === 'w:styles');
358370
const styleTags = wStyles.elements.filter((style) => style.name === 'w:style');
359371
return styleTags.find((tag) => tag.attributes['w:styleId'] === styleId);
360-
};
372+
}
361373

362374
/**
363375
* Get the num ID from the style definition
@@ -390,10 +402,10 @@ function getNumPrRecursive({ node, styleId, docx, seenStyleIds = new Set() }) {
390402
seenStyleIds.add(styleId);
391403
if (!basedOnStyleId) return null;
392404
return getNumPrRecursive({ styleId: basedOnStyleId, docx, seenStyleIds });
393-
};
405+
}
394406

395407
return numPr;
396-
};
408+
}
397409

398410
/**
399411
* Creates a list item node with specified content and marks.

0 commit comments

Comments
 (0)