2022-10-23 22:27:07 +08:00
|
|
|
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') {
|
2022-10-29 00:24:39 +08:00
|
|
|
const code = getCodeString(node.children);
|
|
|
|
const vnode = getVNode(code || '');
|
|
|
|
node.children = vnode;
|
2022-10-23 22:27:07 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-29 00:24:39 +08:00
|
|
|
}
|