Merge pull request #359 from timlrx/fix/code-titles

fix: insert code title relative to parent
This commit is contained in:
Timothy 2022-01-26 18:01:29 +08:00 committed by GitHub
commit f91793a111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@ import { visit } from 'unist-util-visit'
export default function remarkCodeTitles() {
return (tree) =>
visit(tree, 'code', (node, index) => {
visit(tree, 'code', (node, index, parent) => {
const nodeLang = node.lang || ''
let language = ''
let title = ''
@ -26,7 +26,7 @@ export default function remarkCodeTitles() {
data: { _xdmExplicitJsx: true },
}
tree.children.splice(index, 0, titleNode)
parent.children.splice(index, 0, titleNode)
node.lang = language
})
}