Add ID to headings
This commit is contained in:
parent
e4838643d4
commit
f87f742547
10
package.json
10
package.json
|
|
@ -23,13 +23,13 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash.capitalize": "^4.2.9",
|
"@types/lodash.capitalize": "^4.2.9",
|
||||||
"@types/unist": "^2.0.6",
|
"@types/unist": "^2.0.10",
|
||||||
"mdast-util-to-string": "^3.1.1",
|
"mdast-util-to-string": "^4.0.0",
|
||||||
"rehype-raw": "^6.1.1",
|
"rehype-raw": "^6.1.1",
|
||||||
"rehype-stringify": "^9.0.3",
|
"rehype-stringify": "^9.0.4",
|
||||||
"remark-parse": "^10.0.1",
|
"remark-parse": "^10.0.2",
|
||||||
"remark-rehype": "^10.1.0",
|
"remark-rehype": "^10.1.0",
|
||||||
"typescript": "^5.0.2",
|
"typescript": "^5.5.4",
|
||||||
"unified": "^10.1.2"
|
"unified": "^10.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import capitalize from "lodash.capitalize"
|
||||||
import { visit } from "unist-util-visit"
|
import { visit } from "unist-util-visit"
|
||||||
import { toHast } from "mdast-util-to-hast"
|
import { toHast } from "mdast-util-to-hast"
|
||||||
import { toHtml } from "hast-util-to-html"
|
import { toHtml } from "hast-util-to-html"
|
||||||
|
import { toString } from 'mdast-util-to-string';
|
||||||
import { FindAndReplaceList, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
|
import { FindAndReplaceList, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
|
||||||
|
|
||||||
// !? -> optional embedding
|
// !? -> optional embedding
|
||||||
|
|
@ -320,5 +321,13 @@ export default function ofm() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
visit(tree, "heading", (node) => {
|
||||||
|
node.data = {
|
||||||
|
hProperties: {
|
||||||
|
id: toString(node)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue