Skip to content

Commit e381c42

Browse files
committed
fix: prevent all Twoslash poppers from showing by default on load
1 parent 9d3e5e6 commit e381c42

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/slidev/node/syntax/markdown-it/markdown-it-shiki.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ResolvedSlidevOptions } from '@slidev/types'
22
import type { ShikiTransformer } from 'shiki'
33
import { isTruthy } from '@antfu/utils'
44
import { fromHighlighter } from '@shikijs/markdown-it/core'
5+
import { transformerTwoslashConditional } from '../transform/twoslash-conditional'
56
import { escapeVueInCode } from '../transform/utils'
67

78
export default async function MarkdownItShiki({ data: { config }, mode, utils }: ResolvedSlidevOptions) {
@@ -16,6 +17,8 @@ export default async function MarkdownItShiki({ data: { config }, mode, utils }:
1617
},
1718
},
1819
}),
20+
(config.twoslash === true || config.twoslash === mode)
21+
&& transformerTwoslashConditional(),
1922
{
2023
pre(pre) {
2124
this.addClassToHast(pre, 'slidev-code')
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { ShikiTransformer } from 'shiki'
2+
3+
/**
4+
* Custom Twoslash transformer that replaces :shown='true' with conditional logic
5+
* to prevent poppers from being shown during preload
6+
*/
7+
export function transformerTwoslashConditional(): ShikiTransformer {
8+
return {
9+
name: 'slidev:twoslash-conditional',
10+
postprocess(code) {
11+
return code.replace(
12+
/(<v-menu[^>]*):shown=['"]true['"]/g,
13+
'$1:shown="false"',
14+
)
15+
},
16+
}
17+
}

0 commit comments

Comments
 (0)