Skip to content

Commit a992f68

Browse files
fix: formatting issues (#773)
1 parent 34ec252 commit a992f68

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ export function handleVRectImport({ rect, pNode }) {
8383
// Extract dimensions for the size attribute
8484
const size = {};
8585
if (parsedStyle.width !== undefined) {
86-
size.width = parsePointsToPixels(parsedStyle.width);
86+
const inlineWidth = parsePointsToPixels(parsedStyle.width);
87+
size.width = inlineWidth;
8788

8889
// Check for full page width identifier and adjust width to be 100%
89-
if (rectAttrs['o:hr'] === 't') {
90+
if (rectAttrs['o:hr'] === 't' && !inlineWidth) {
9091
size.width = '100%';
9192
}
9293
}
@@ -123,6 +124,8 @@ export function handleVRectImport({ rect, pNode }) {
123124
const pPr = pNode.elements?.find((el) => el.name === 'w:pPr');
124125
const spacingElement = pPr?.elements?.find((el) => el.name === 'w:spacing');
125126
const spacingAttrs = spacingElement?.attributes || {};
127+
const inLineIndentTag = pPr?.elements?.find((el) => el.name === 'w:ind');
128+
const inLineIndent = inLineIndentTag?.attributes || {};
126129

127130
// Parse spacing using the same logic as paragraphNodeImporter
128131
const spacing = {};
@@ -131,6 +134,22 @@ export function handleVRectImport({ rect, pNode }) {
131134
if (spacingAttrs['w:line']) spacing.line = twipsToLines(spacingAttrs['w:line']);
132135
if (spacingAttrs['w:lineRule']) spacing.lineRule = spacingAttrs['w:lineRule'];
133136

137+
const indent = {
138+
left: 0,
139+
right: 0,
140+
firstLine: 0,
141+
hanging: 0,
142+
};
143+
const leftIndent = inLineIndent?.['w:left'];
144+
const rightIndent = inLineIndent?.['w:right'];
145+
146+
if (leftIndent) {
147+
indent.left = twipsToPixels(leftIndent);
148+
}
149+
if (rightIndent) {
150+
indent.right = twipsToPixels(rightIndent);
151+
}
152+
134153
return {
135154
type: 'paragraph',
136155
content: [
@@ -142,6 +161,7 @@ export function handleVRectImport({ rect, pNode }) {
142161
attrs: {
143162
spacing: Object.keys(spacing).length > 0 ? spacing : undefined,
144163
rsidRDefault: pNode.attributes?.['w:rsidRDefault'],
164+
indent,
145165
},
146166
};
147167
}
@@ -261,7 +281,7 @@ export function parsePointsToPixels(value) {
261281
return 0;
262282
}
263283
const points = parseFloat(val);
264-
return Math.round(points * 1.33);
284+
return Math.ceil(points * 1.33);
265285
}
266286

267287
// Handle pixel values

packages/super-editor/src/extensions/linked-styles/helpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ export const generateLinkedStyleString = (linkedStyle, basedOnStyle, node, paren
154154
if (!listTypes.includes(node.type.name)) {
155155
markValue[key] = value;
156156
}
157+
} else if (key === 'color' && node) {
158+
if (!listTypes.includes(node.type.name)) {
159+
markValue[key] = value;
160+
}
157161
} else if (typeof value === 'string') {
158162
markValue[key] = value;
159163
}

packages/super-editor/src/tests/import/rectImporter.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ describe('RectImporter', () => {
260260
expect(contentBlock.attrs.vmlAttributes.hr).toBe('t');
261261
expect(contentBlock.attrs.vmlAttributes.stroked).toBe('t');
262262

263-
// If hr is true, the width should be 100%
264-
expect(contentBlock.attrs.size.width).toBe('100%');
263+
// If hr is true, the width should be 100% - to double check
264+
expect(contentBlock.attrs.size.width).toBe(266);
265265
});
266266

267267
it('should handle v:rect with o:hr attribute for full page width', () => {
@@ -277,7 +277,7 @@ describe('RectImporter', () => {
277277
const result = handleVRectImport({ rect, pNode });
278278

279279
const contentBlock = result.content[0];
280-
expect(contentBlock.attrs.size.width).toBe('100%');
280+
expect(contentBlock.attrs.size.width).toBe(133);
281281
expect(contentBlock.attrs.horizontalRule).toBe(true);
282282
});
283283

@@ -353,7 +353,7 @@ describe('RectImporter', () => {
353353
});
354354

355355
it('should round pixel values correctly', () => {
356-
expect(parsePointsToPixels('10pt')).toBe(13); // 10 * 1.33 = 13.3, rounded to 13
356+
expect(parsePointsToPixels('10pt')).toBe(14); // 10 * 1.33 = 13.3, rounded to 14
357357
expect(parsePointsToPixels('15pt')).toBe(20); // 15 * 1.33 = 19.95, rounded to 20
358358
});
359359
});

0 commit comments

Comments
 (0)