Initial commit.
This commit is contained in:
31
implementations/js/packages/blocks/markdown/markdown.js
Normal file
31
implementations/js/packages/blocks/markdown/markdown.js
Normal file
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
||||
2744
implementations/js/packages/blocks/markdown/package-lock.json
generated
Normal file
2744
implementations/js/packages/blocks/markdown/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
implementations/js/packages/blocks/markdown/package.json
Normal file
17
implementations/js/packages/blocks/markdown/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@terrace/block-markdown",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"test": "vitest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitest": "^0.15.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"rehype-stringify": "^9.0.3",
|
||||
"remark-parse": "^10.0.1",
|
||||
"remark-rehype": "^10.1.0",
|
||||
"unified": "^10.1.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user