Skip to content

Commit de69756

Browse files
authored
Refactor Discourse Datalog Translators to strip leading hashes from node tags (#541)
1 parent 08113a9 commit de69756

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

apps/roam/src/utils/registerDiscourseDatalogTranslators.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ const registerDiscourseDatalogTranslators = () => {
101101
const isACandidateCallback: Parameters<
102102
typeof registerDatalogTranslator
103103
>[0]["callback"] = ({ source, target }) => {
104+
const stripLeadingHash = (value: string): string =>
105+
value.startsWith("#") ? value.slice(1) : value;
106+
104107
const nodeByTypeOrText = Object.fromEntries([
105108
...discourseNodes.map((n) => [n.type, n] as const),
106109
...discourseNodes.map((n) => [n.text, n] as const),
@@ -129,7 +132,10 @@ const registerDiscourseDatalogTranslators = () => {
129132
},
130133
],
131134
},
132-
...getTitleDatalog({ source: variableRef, target: node.tag }),
135+
...getTitleDatalog({
136+
source: variableRef,
137+
target: stripLeadingHash(node.tag),
138+
}),
133139
],
134140
};
135141
}),
@@ -153,7 +159,10 @@ const registerDiscourseDatalogTranslators = () => {
153159
},
154160
],
155161
},
156-
...getTitleDatalog({ source: variableRef, target: targetNodeTag }),
162+
...getTitleDatalog({
163+
source: variableRef,
164+
target: stripLeadingHash(targetNodeTag),
165+
}),
157166
];
158167
};
159168
const unregisters = new Set<() => void>();

0 commit comments

Comments
 (0)