fix: missing spaces before and after the a tag

This commit is contained in:
DIYgod 2023-04-18 01:23:58 +01:00
parent 037698f2ea
commit a8a5e76a4a
No known key found for this signature in database
1 changed files with 19 additions and 14 deletions

View File

@ -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
}