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.
This commit is contained in:
Claude 2025-11-06 03:23:27 +00:00
parent 8f0658e90d
commit f411a3e706
No known key found for this signature in database
1 changed files with 6 additions and 4 deletions

View File

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