File size: 509 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/**
* Credit to https://ped.ro/writing/code-blocks-but-better
*/
import { toHtml } from 'hast-util-to-html'
import { unified } from 'unified'
import parse from 'rehype-parse'
const CALLOUT = /__(.*?)__/g
export default function (code) {
const html = toHtml(code)
const result = html.replace(
CALLOUT,
(_, text) => `<span class="highlight-word">${text}</span>`
)
const hast = unified()
.use(parse, { emitParseErrors: true, fragment: true })
.parse(result)
return hast.children
}
|