Skip to content

Commit 482fd4b

Browse files
committed
fix(plugin-tikz): remove wrapping pre
1 parent dfc8812 commit 482fd4b

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

packages/plugin-tikz/src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@ const tikzTransformer: UnifiedPlugin<
8686
hast.Root
8787
> = ({ carta, options }) => {
8888
return async function (tree) {
89-
visit(tree, (node, index, parent) => {
89+
visit(tree, (pre, index, parent) => {
9090
if (typeof document === 'undefined') {
9191
// Cannot run outside the browser
9292
return;
9393
}
9494

95-
if (node.type !== 'element') return;
96-
const element = node as hast.Element;
95+
if (pre.type !== 'element') return;
96+
const preElement = pre as hast.Element;
97+
if (preElement.tagName !== 'pre') return;
98+
const element = pre.children.at(0) as hast.Element | undefined;
99+
if (!element) return;
100+
97101
if (element.tagName !== 'code') return;
98102
if (!element.properties['className']) return;
99103
if (!(element.properties['className'] as string[]).includes('language-tikz')) return;
@@ -130,6 +134,7 @@ const tikzTransformer: UnifiedPlugin<
130134
}
131135

132136
const hastNode = fromDom(container) as hast.Element;
137+
133138
parent?.children.splice(index!, 1, hastNode);
134139

135140
return [SKIP, index!];

0 commit comments

Comments
 (0)