Joshua Bemenderfer 0196cd5c87 Reorganize repo.
2022-11-01 14:57:07 -04:00

35 lines
821 B
JavaScript

import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
export default function (config) {
return async function ({ lineData, ended, next }) {
if (ended) return ''
const blockLevel = lineData.level
let md = ''
function finalize() {
return unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeStringify)
.process(md)
}
async function markdownContents({ line, lineData, ended }) {
if (ended || lineData.level <= blockLevel) {
const final = String(await finalize())
return final
}
md += line.slice(blockLevel + 1) + '\n'
return markdownContents(await next())
}
return markdownContents(await next())
}
}