File tree 2 files changed +22
-6
lines changed
2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,12 @@ export interface MarkdownOptions extends MarkdownIt.Options {
177
177
*/
178
178
math ?: boolean | any
179
179
image ?: ImageOptions
180
+ /**
181
+ * Allows disabling the github alerts plugin
182
+ * @default true
183
+ * @see https://vitepress.dev/guide/markdown#github-flavored-alerts
184
+ */
185
+ gfmAlerts ?: boolean
180
186
}
181
187
182
188
export type MarkdownRenderer = MarkdownIt
@@ -209,7 +215,6 @@ export const createMarkdownRenderer = async (
209
215
. use ( preWrapperPlugin , { hasSingleTheme } )
210
216
. use ( snippetPlugin , srcDir )
211
217
. use ( containerPlugin , { hasSingleTheme } , options . container )
212
- . use ( gitHubAlertsPlugin , options . container )
213
218
. use ( imagePlugin , options . image )
214
219
. use (
215
220
linkPlugin ,
@@ -218,6 +223,10 @@ export const createMarkdownRenderer = async (
218
223
)
219
224
. use ( lineNumberPlugin , options . lineNumbers )
220
225
226
+ if ( options . gfmAlerts !== false ) {
227
+ md . use ( gitHubAlertsPlugin )
228
+ }
229
+
221
230
// 3rd party plugins
222
231
if ( ! options . attrs ?. disable ) {
223
232
md . use ( attrsPlugin , options . attrs )
Original file line number Diff line number Diff line change @@ -22,12 +22,19 @@ export const gitHubAlertsPlugin = (
22
22
const tokens = state . tokens
23
23
for ( let i = 0 ; i < tokens . length ; i ++ ) {
24
24
if ( tokens [ i ] . type === 'blockquote_open' ) {
25
- const open = tokens [ i ]
26
25
const startIndex = i
27
- while ( tokens [ i ] ?. type !== 'blockquote_close' && i <= tokens . length )
28
- i += 1
29
- const close = tokens [ i ]
30
- const endIndex = i
26
+ const open = tokens [ startIndex ]
27
+ let endIndex = i + 1
28
+ while (
29
+ ! (
30
+ tokens [ endIndex ] . type === 'blockquote_close' &&
31
+ tokens [ endIndex ] . level === open . level
32
+ ) &&
33
+ endIndex < tokens . length
34
+ )
35
+ endIndex ++
36
+ if ( endIndex === tokens . length ) continue
37
+ const close = tokens [ endIndex ]
31
38
const firstContent = tokens
32
39
. slice ( startIndex , endIndex + 1 )
33
40
. find ( ( token ) => token . type === 'inline' )
You can’t perform that action at this time.
0 commit comments