32 lines
734 B
JavaScript
32 lines
734 B
JavaScript
import {unified} from 'unified'
|
|
import remarkParse from 'remark-parse'
|
|
import remarkRehype from 'remark-rehype'
|
|
import rehypeStringify from 'rehype-stringify'
|
|
|
|
export default function (line, lineData, doc) {
|
|
const blockLevel = lineData.level
|
|
|
|
let md = ''
|
|
|
|
function finalize() {
|
|
return unified()
|
|
.use(remarkParse)
|
|
.use(remarkRehype)
|
|
.use(rehypeStringify)
|
|
.process(md)
|
|
}
|
|
|
|
async function markdownContents(line, lineData, doc) {
|
|
if (lineData.level <= blockLevel) {
|
|
const final = String(await finalize())
|
|
page.body += final
|
|
return doc.repeat(baseHandler)
|
|
}
|
|
|
|
md += line.slice(blockLevel + 1) + '\n'
|
|
return doc.next(markdownContents)
|
|
}
|
|
|
|
return doc.next(markdownContents)
|
|
}
|