fix: fix preview html meta issue.
This commit is contained in:
parent
75fece7aab
commit
cb704eed88
@ -53,12 +53,12 @@ export function create(str = '', options = {}) {
|
|||||||
});
|
});
|
||||||
// 放在 rehypeDocument 前面
|
// 放在 rehypeDocument 前面
|
||||||
dt.unshift(rehypeRaw);
|
dt.unshift(rehypeRaw);
|
||||||
|
dt.unshift(rehypePreviewHTML);
|
||||||
return dt;
|
return dt;
|
||||||
}
|
}
|
||||||
return plugins;
|
return plugins;
|
||||||
},
|
},
|
||||||
rewrite: (node, index, parent) => {
|
rewrite: (node, index, parent) => {
|
||||||
rehypePreviewHTML(node, parent);
|
|
||||||
rehypeTitle(node, options.filename);
|
rehypeTitle(node, options.filename);
|
||||||
homeCardIcons(node, parent, options.isHome);
|
homeCardIcons(node, parent, options.isHome);
|
||||||
tooltips(node, index, parent);
|
tooltips(node, index, parent);
|
||||||
|
@ -1,13 +1,22 @@
|
|||||||
|
import { visit } from 'unist-util-visit';
|
||||||
import { getCodeString } from 'rehype-rewrite';
|
import { getCodeString } from 'rehype-rewrite';
|
||||||
import { getVNode } from './getSVGNode.mjs';
|
import { getVNode } from './getSVGNode.mjs';
|
||||||
|
|
||||||
export function rehypePreviewHTML(node, parent) {
|
export function rehypePreviewHTML() {
|
||||||
if (node.type === 'element' && node.tagName === 'pre' && node.properties?.className?.includes('language-html')) {
|
return (tree) => {
|
||||||
|
visit(tree, (node, index, parent) => {
|
||||||
|
if (node.type === 'element' && node.tagName === 'pre') {
|
||||||
const child = node.children[0];
|
const child = node.children[0];
|
||||||
if (child?.tagName === 'code' && child.data?.meta === 'preview') {
|
if (
|
||||||
const code = getCodeString(node.children);
|
child.properties?.className?.includes('language-html') &&
|
||||||
|
child?.tagName === 'code' &&
|
||||||
|
child.data?.meta === 'preview'
|
||||||
|
) {
|
||||||
|
const code = getCodeString(child.children);
|
||||||
const vnode = getVNode(code || '');
|
const vnode = getVNode(code || '');
|
||||||
node.children = vnode;
|
node.children = vnode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user