Skip to content

Commit eac1377

Browse files
Make explicitTrigger 'mint-twoslash' and add support when parsing meta string
1 parent 573a7d0 commit eac1377

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/mdx/src/plugins/rehype/rehypeSyntaxHighlighting.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const twoslashOptions: TransformerTwoslashOptions = {
4343
},
4444
renderer: rendererRich(),
4545
langs: ['ts', 'typescript', 'js', 'javascript', 'tsx', 'jsx'],
46-
explicitTrigger: true,
46+
explicitTrigger: /mint-twoslash/,
4747
twoslashOptions: { compilerOptions: twoslashCompilerOptions },
4848
};
4949

@@ -147,8 +147,18 @@ const traverseNode = (
147147
try {
148148
const code = toString(node);
149149

150+
const meta = node.data?.meta?.split(' ') ?? [];
151+
const twoslashIndex = meta.findIndex((str) => str.toLowerCase() === 'mint-twoslash');
152+
const shouldUseTwoslash = twoslashIndex > -1;
153+
154+
if (node.data && node.data.meta && shouldUseTwoslash) {
155+
meta.splice(twoslashIndex, 1);
156+
node.data.meta = meta.join(' ').trim() || undefined;
157+
}
158+
150159
const hast = highlighter.codeToHast(code, {
151160
lang: lang ?? DEFAULT_LANG,
161+
meta: shouldUseTwoslash ? { __raw: 'mint-twoslash' } : undefined,
152162
themes: {
153163
light:
154164
options.themes?.light ??

0 commit comments

Comments
 (0)