From f411a3e7063f642bea67939a3ab42b9dbc74d28a Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 6 Nov 2025 03:23:27 +0000 Subject: [PATCH] fix(web): fix tag syntax rendering on first line The remarkTag plugin was only visiting "text" nodes, which caused issues when content starting with #tag might be parsed as a heading node by the markdown parser. Changed the visitor to process all nodes and check for text nodes explicitly, ensuring tags are parsed correctly regardless of their position in the content. This fixes the issue where tags on the first line of content were not being rendered as clickable tag elements. --- web/src/utils/remark-plugins/remark-tag.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web/src/utils/remark-plugins/remark-tag.ts b/web/src/utils/remark-plugins/remark-tag.ts index 4f1866c6d..ea3cd81fd 100644 --- a/web/src/utils/remark-plugins/remark-tag.ts +++ b/web/src/utils/remark-plugins/remark-tag.ts @@ -80,10 +80,13 @@ function parseTagsFromText(text: string): Array<{ type: "text" | "tag"; value: s */ export const remarkTag = () => { return (tree: Root) => { - visit(tree, "text", (node: Text, index, parent) => { - if (!parent || index === null) return; + // Process text nodes in all node types (paragraphs, headings, etc.) + visit(tree, (node: any, index, parent) => { + // Only process text nodes that have a parent and index + if (node.type !== "text" || !parent || index === null) return; - const text = node.value; + const textNode = node as Text; + const text = textNode.value; const segments = parseTagsFromText(text); // If no tags found, leave node as-is @@ -118,7 +121,6 @@ export const remarkTag = () => { }); // Replace the current node with the new nodes - // @ts-expect-error - mdast types are complex, this is safe parent.children.splice(index, 1, ...newNodes); }); };