Code-headers plugin rewrite (#37654)
Co-authored-by: Peter Bengtsson <peterbe@github.com>
This commit is contained in:
@@ -7,17 +7,26 @@
|
||||
|
||||
import { visit } from 'unist-util-visit'
|
||||
|
||||
const matcher = (node) => node.type === 'code' && node.lang && node.meta
|
||||
const matcher = (node) => node.type === 'code' && node.lang
|
||||
|
||||
export default function parseInfoString() {
|
||||
return (tree) => {
|
||||
visit(tree, matcher, (node) => {
|
||||
node.meta = strToObj(node.meta)
|
||||
|
||||
// Temporary, change {:copy} to ` copy` to avoid conflict in styles.
|
||||
// We may end up enabling copy on all code examples later.
|
||||
const copyTag = '{:copy}'
|
||||
if (node.lang.includes(copyTag)) {
|
||||
node.meta.copy = true
|
||||
node.lang = node.lang.replace(copyTag, '')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function strToObj(str) {
|
||||
if (!str) return {}
|
||||
return Object.fromEntries(
|
||||
str
|
||||
.split(/\s+/g)
|
||||
|
||||
Reference in New Issue
Block a user