We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent add5007 commit e74a555Copy full SHA for e74a555
plugins/gatsby-remark-header-custom-ids/index.js
@@ -25,7 +25,16 @@ module.exports = (
25
slugs.reset();
26
27
visit(markdownAST, 'heading', node => {
28
- const id = slugs.slug(toString(node), maintainCase);
+ // Support custom-id syntax.
29
+ const rawHeader = toString(node);
30
+ const match = /^.+(\s*\{#([a-z0-9\-_]+?)\}\s*)$/.exec(rawHeader);
31
+ const id = match ? match[2] : slugs.slug(rawHeader, maintainCase);
32
+ if (match) {
33
+ // Remove the custom ID part from the text node.
34
+ const lastNode = node.children[node.children.length - 1];
35
+ lastNode.value = lastNode.value.replace(match[1], '');
36
+ }
37
+
38
const data = patch(node, 'data', {});
39
40
patch(data, 'id', id);
0 commit comments