Reorganize repo.
This commit is contained in:
21
packages/js/block-markdown/LICENSE.md
Normal file
21
packages/js/block-markdown/LICENSE.md
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Joshua Michael Bemenderfer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
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())
|
||||
}
|
||||
}
|
||||
2812
packages/js/block-markdown/package-lock.json
generated
Normal file
2812
packages/js/block-markdown/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
packages/js/block-markdown/package.json
Normal file
18
packages/js/block-markdown/package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@terrace/block-markdown",
|
||||
"type": "module",
|
||||
"version": "0.0.1",
|
||||
"main": "./index.js",
|
||||
"scripts": {
|
||||
"test": "vitest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitest": "^0.24.5"
|
||||
},
|
||||
"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