Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions packages/superdoc/src/stores/comments-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ export const useCommentsStore = defineStore('comments', () => {
if (__IS_DEBUG__) console.debug('[processLoadedDocxComments] processing comments...', comments);

comments.forEach((comment) => {
const htmlContent = getHTmlFromComment(comment.textJson);
if (!htmlContent) return;

const importedName = `${comment.creatorName.replace('(imported)', '')} (imported)`
const newComment = useComment({
fileId: documentId,
Expand Down Expand Up @@ -522,14 +525,22 @@ export const useCommentsStore = defineStore('comments', () => {
* @returns {string} The HTML content
*/
const getHTmlFromComment = (commentTextJson) => {
const editor = new Editor({
mode: 'text',
isHeadless: true,
content: commentTextJson,
loadFromSchema: true,
extensions: getRichTextExtensions(),
});
return editor.getHTML();
// If no content, we can't convert and its not a valid comment
if (!commentTextJson.content?.length) return;

try {
const editor = new Editor({
mode: 'text',
isHeadless: true,
content: commentTextJson,
loadFromSchema: true,
extensions: getRichTextExtensions(),
});
return editor.getHTML();
} catch (error) {
console.warn('Failed to convert comment', error);
return;
};
};

return {
Expand Down