Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix(web): fix tag syntax rendering on first line (#5226)

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