Skip to content

Commit 452cd2f

Browse files
authored
fix(editor): remove style components (#328)
1 parent ca2f696 commit 452cd2f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/app/src/utils/tiptap/tiptapToMdc.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,25 @@ async function applyShikiSyntaxHighlighting(mdc: MDCRoot, theme: SyntaxHighlight
452452
(n: unknown) => { Object.assign(n as MDCNode, { tag: (n as Element).tagName, props: (n as Element).properties, tagName: undefined, properties: undefined }) },
453453
)
454454

455-
// Remove empty newline text nodes
455+
// Remove empty newline text nodes and style elements
456456
visit(
457457
mdc,
458458
(n: unknown) => (n as MDCElement).tag === 'pre',
459459
(n: unknown) => {
460-
((n as MDCElement).children[0] as MDCElement).children = ((n as MDCElement).children[0] as MDCElement).children.filter((child: MDCNode) => child.type !== 'text' || child.value.trim())
460+
((n as MDCElement).children[0] as MDCElement).children = ((n as MDCElement).children[0] as MDCElement).children.filter((child: MDCNode) => {
461+
// Remove style elements added by Shiki
462+
if (child.type === 'element' && (child as MDCElement).tag === 'style') {
463+
return false
464+
}
465+
466+
// Remove empty text nodes
467+
if (child.type === 'text' && !child.value.trim()) {
468+
return false
469+
}
470+
471+
// Keep everything else
472+
return true
473+
})
461474
},
462475
)
463476
}

0 commit comments

Comments
 (0)