Reorganize repo.
This commit is contained in:
34
packages/js/block-markdown/index.js
Normal file
34
packages/js/block-markdown/index.js
Normal file
@@ -0,0 +1,34 @@
|
||||
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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user