From 69886cd9fb90f5cdea2f46eb59fb3459bc771a9c Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Wed, 23 Apr 2025 10:22:11 +0100 Subject: [PATCH] remove comment mark in shares --- apps/server/src/common/helpers/prosemirror/utils.ts | 13 +++++++++++++ apps/server/src/core/share/share.service.ts | 10 ++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/server/src/common/helpers/prosemirror/utils.ts b/apps/server/src/common/helpers/prosemirror/utils.ts index aaadcd56..babedbed 100644 --- a/apps/server/src/common/helpers/prosemirror/utils.ts +++ b/apps/server/src/common/helpers/prosemirror/utils.ts @@ -1,6 +1,7 @@ import { Node } from '@tiptap/pm/model'; import { jsonToNode } from '../../../collaboration/collaboration.util'; import { validate as isValidUUID } from 'uuid'; +import { Transform } from '@tiptap/pm/transform'; export interface MentionNode { id: string; @@ -94,4 +95,16 @@ export function getAttachmentIds(prosemirrorJson: any) { }); return attachmentIds; +} + +export function removeMarkTypeFromDoc(doc: Node, markName: string): Node { + const { schema } = doc.type; + const markType = schema.marks[markName]; + + if (!markType) { + return doc; + } + + const tr = new Transform(doc).removeMark(0, doc.content.size, markType); + return tr.doc; } \ No newline at end of file diff --git a/apps/server/src/core/share/share.service.ts b/apps/server/src/core/share/share.service.ts index a9140c0b..d71b6acd 100644 --- a/apps/server/src/core/share/share.service.ts +++ b/apps/server/src/core/share/share.service.ts @@ -15,6 +15,7 @@ import { getAttachmentIds, getProsemirrorContent, isAttachmentNode, + removeMarkTypeFromDoc, } from '../../common/helpers/prosemirror/utils'; import { Node } from '@tiptap/pm/model'; import { ShareRepo } from '@docmost/db/repos/share/share.repo'; @@ -223,11 +224,7 @@ export class ShareService { .end() .as('found'), ]) - .where( - isValidUUID(childPageId) ? 'id' : 'slugId', - '=', - childPageId, - ) + .where(isValidUUID(childPageId) ? 'id' : 'slugId', '=', childPageId) .unionAll((exp) => exp .selectFrom('pages as p') @@ -292,6 +289,7 @@ export class ShareService { updateAttachmentAttr(node, 'url', token); }); - return doc.toJSON(); + const removeCommentMarks = removeMarkTypeFromDoc(doc, 'comment'); + return removeCommentMarks.toJSON(); } }