feat: HTML code preview is supported in markdown.

This commit is contained in:
jaywcjlove
2022-10-23 22:27:07 +08:00
parent fdcfcb287b
commit a478fbb888
6 changed files with 44 additions and 5 deletions

View File

@ -3,11 +3,19 @@ import rehypeParse from 'rehype-parse';
import {unified} from 'unified';
import { VFile } from 'vfile';
export function getSVGNode(iconPath) {
export function getSVGNode(iconPath, space = 'svg') {
const svgStr = fs.readFileSync(iconPath);
const processor = unified().use(rehypeParse,{ fragment: true, space: "svg" })
const processor = unified().use(rehypeParse,{ fragment: true, space })
const file = new VFile();
file.value = svgStr.toString();
const hastNode = processor.runSync(processor.parse(file), file);
return hastNode.children || []
}
export function getVNode(str = '', space = 'html') {
const processor = unified().use(rehypeParse,{ fragment: true, space })
const file = new VFile();
file.value = str.toString();
const hastNode = processor.runSync(processor.parse(file), file);
return hastNode.children || []
}