Skip to content

Commit 1580303

Browse files
helpz: dummy support for custom id for headers
1 parent 025fd26 commit 1580303

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

_helpz/generate.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ function genGlobalVars(site, zconf) {
242242
};
243243
}
244244

245+
const customIdRegex = / {#(?<id>.+)}$/;
246+
245247
enablePages.forEach((page) => {
246248
const conf = loadConf(page, language);
247249
const mdContent = [];
@@ -408,6 +410,18 @@ enablePages.forEach((page) => {
408410
node.position = null;
409411
return visitor.SKIP;
410412
});
413+
visitor.visit(mdast, "heading", (node) => {
414+
const lastChild = node.children[node.children.length - 1];
415+
let id = null;
416+
if (lastChild && lastChild.type === "text") {
417+
const match = customIdRegex.exec(lastChild.value);
418+
if (match) {
419+
id = match.groups.id;
420+
lastChild.value = lastChild.value.replace(customIdRegex, "");
421+
}
422+
}
423+
// TODO: handle id
424+
});
411425
const modifiedContent = toMarkdown(mdast);
412426
mdContent.push(modifiedContent);
413427
});

0 commit comments

Comments
 (0)