From a8a5e76a4aef0fa5d5b5d49fcf88f3d84301dad3 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 18 Apr 2023 01:23:58 +0100 Subject: [PATCH] fix: missing spaces before and after the a tag --- src/markdown/index.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/markdown/index.ts b/src/markdown/index.ts index 602f07d2..d28df573 100644 --- a/src/markdown/index.ts +++ b/src/markdown/index.ts @@ -128,21 +128,26 @@ export const renderPageContent = ( if (node.children) { node.children = node.children.flatMap((child: any) => { if (child.type === "text") { - const parts = toText(child).split(/(@[\w-]+)/g) - return parts.map((part) => { - if (part.startsWith("@")) { - return { - type: "element", - tagName: "mention", - children: [{ type: "text", value: part }], + const mentionRegex = /(@[\w-]+)/g + if (mentionRegex.test(child.value)) { + const parts = child.value.split(mentionRegex) + return parts.map((part: string) => { + if (part.startsWith("@")) { + return { + type: "element", + tagName: "mention", + children: [{ type: "text", value: part }], + } + } else { + return { + type: "text", + value: part, + } } - } else { - return { - type: "text", - value: part, - } - } - }) + }) + } else { + return child + } } else { return child }