Skip to content

Commit fd5c81d

Browse files
committed
HAR-9211 Comments export fixes
1 parent 4ba5902 commit fd5c81d

4 files changed

Lines changed: 24 additions & 17 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class SuperConverter {
358358
});
359359
updatedXml = { ...documentXml };
360360
commentsRels = relationships;
361-
};
361+
}
362362

363363
this.convertedXml = { ...this.convertedXml, ...updatedXml };
364364

@@ -390,8 +390,10 @@ class SuperConverter {
390390
const relsData = this.convertedXml['word/_rels/document.xml.rels'];
391391
const relationships = relsData.elements.find((x) => x.name === 'Relationships');
392392
const newRels = [];
393-
394-
let largestId = Math.max(...relationships.elements.map((el) => Number(el.attributes.Id.replace('rId', ''))));
393+
394+
const regex = /rId|mi/g;
395+
let largestId = Math.max(...relationships.elements.map((el) => Number(el.attributes.Id.replace(regex, ''))));
396+
395397
rels.forEach((rel) => {
396398
const existingId = rel.attributes.Id;
397399
const existingTarget = relationships.elements.find((el) => el.attributes.Target === rel.attributes.Target);
@@ -400,7 +402,7 @@ class SuperConverter {
400402
if (existingTarget && !isNewMedia) {
401403
return;
402404
}
403-
405+
404406
// Update the target to escape ampersands
405407
rel.attributes.Target = rel.attributes?.Target?.replace(/&/g, '&');
406408

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,11 +1604,14 @@ function translateFieldAnnotation(params) {
16041604

16051605
export function translateHardBreak() {
16061606
return {
1607-
name: 'w:br',
1608-
type: 'element',
1609-
attributes: { 'w:type': 'page' }
1607+
name: 'w:r',
1608+
elements: [{
1609+
name: 'w:br',
1610+
type: 'element',
1611+
attributes: { 'w:type': 'page' }
1612+
}]
16101613
};
1611-
};
1614+
}
16121615

16131616
export class DocxExporter {
16141617
constructor(converter) {

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ export function translateCommentNode(params, type) {
3838

3939
let commentSchema = getCommentSchema(type, commentIndex);
4040
if (type === 'End') {
41-
const commentReference = { name: 'w:commentReference', attributes: { 'w:id': String(commentIndex) } };
41+
const commentReference = {
42+
name: 'w:r',
43+
elements: [{ name: 'w:commentReference', attributes: { 'w:id': String(commentIndex) } }]
44+
};
4245
commentSchema = [commentSchema, commentReference];
43-
};
46+
}
4447
return commentSchema;
45-
};
48+
}
4649

4750

4851
/**
@@ -185,15 +188,14 @@ export const updateCommentsExtendedXml = (comments = [], commentsExtendedXml) =>
185188
const attributes = {
186189
'w15:paraId': comment.commentParaId,
187190
'w15:done': comment.resolvedTime ? '1' : '0',
188-
'w:rsid': comment.commentId || comment.importedId,
189191
};
190192

191193
const parentId = comment.parentCommentId;
192194
if (parentId) {
193195
const parentComment = comments.find((c) => c.commentId === parentId);
194196
const parentParaId = parentComment.commentParaId;
195197
attributes['w15:paraIdParent'] = parentParaId;
196-
};
198+
}
197199

198200
return {
199201
type: 'element',
@@ -240,7 +242,7 @@ export const updateCommentsIdsAndExtensible = (comments = [], commentsIds, exten
240242
"name": "w16cex:commentExtensible",
241243
"attributes": {
242244
"w16cex:durableId": newDurableId,
243-
"w16cex:dateUtc": "2025-03-06T23:32:00Z"
245+
"w16cex:dateUtc": toIsoNoFractional()
244246
}
245247
};
246248
extensibleUpdated.elements[0].elements.push(newExtensible);
@@ -353,8 +355,8 @@ export const prepareCommentsXmlFilesForExport = ({
353355
if (exportType === 'clean') {
354356
const documentXml = removeCommentsFilesFromConvertedXml(convertedXml);
355357
return { documentXml, relationships };
356-
};
357-
358+
}
359+
358360
// Initialize comments files with empty content
359361
const updatedXml = generateConvertedXmlWithCommentFiles(convertedXml);
360362

packages/superdoc/src/core/SuperDoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export class SuperDoc extends EventEmitter {
505505
const comments = [];
506506
if (commentsType !== 'clean') {
507507
comments.push(...this.commentsStore?.translateCommentsForExport());
508-
};
508+
}
509509

510510
const docxPromises = [];
511511
this.superdocStore.documents.forEach((doc) => {

0 commit comments

Comments
 (0)