mirror of
https://github.com/jaywcjlove/reference.git
synced 2025-06-17 12:41:20 +08:00
fix: fix preview html meta issue.
This commit is contained in:
@ -1,13 +1,22 @@
|
||||
import { visit } from 'unist-util-visit';
|
||||
import { getCodeString } from 'rehype-rewrite';
|
||||
import { getVNode } from './getSVGNode.mjs';
|
||||
|
||||
export function rehypePreviewHTML(node, parent) {
|
||||
if (node.type === 'element' && node.tagName === 'pre' && node.properties?.className?.includes('language-html')) {
|
||||
const child = node.children[0];
|
||||
if (child?.tagName === 'code' && child.data?.meta === 'preview') {
|
||||
const code = getCodeString(node.children);
|
||||
const vnode = getVNode(code || '');
|
||||
node.children = vnode;
|
||||
}
|
||||
}
|
||||
export function rehypePreviewHTML() {
|
||||
return (tree) => {
|
||||
visit(tree, (node, index, parent) => {
|
||||
if (node.type === 'element' && node.tagName === 'pre') {
|
||||
const child = node.children[0];
|
||||
if (
|
||||
child.properties?.className?.includes('language-html') &&
|
||||
child?.tagName === 'code' &&
|
||||
child.data?.meta === 'preview'
|
||||
) {
|
||||
const code = getCodeString(child.children);
|
||||
const vnode = getVNode(code || '');
|
||||
node.children = vnode;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user