diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index 61acb9db..9554ad7f 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -177,6 +177,12 @@ export interface MarkdownOptions extends MarkdownIt.Options { */ math?: boolean | any image?: ImageOptions + /** + * Allows disabling the github alerts plugin + * @default true + * @see https://vitepress.dev/guide/markdown#github-flavored-alerts + */ + gfmAlerts?: boolean } export type MarkdownRenderer = MarkdownIt @@ -209,7 +215,6 @@ export const createMarkdownRenderer = async ( .use(preWrapperPlugin, { hasSingleTheme }) .use(snippetPlugin, srcDir) .use(containerPlugin, { hasSingleTheme }, options.container) - .use(gitHubAlertsPlugin, options.container) .use(imagePlugin, options.image) .use( linkPlugin, @@ -218,6 +223,10 @@ export const createMarkdownRenderer = async ( ) .use(lineNumberPlugin, options.lineNumbers) + if (options.gfmAlerts !== false) { + md.use(gitHubAlertsPlugin) + } + // 3rd party plugins if (!options.attrs?.disable) { md.use(attrsPlugin, options.attrs) diff --git a/src/node/markdown/plugins/githubAlerts.ts b/src/node/markdown/plugins/githubAlerts.ts index fd084f59..48047b19 100644 --- a/src/node/markdown/plugins/githubAlerts.ts +++ b/src/node/markdown/plugins/githubAlerts.ts @@ -22,12 +22,19 @@ export const gitHubAlertsPlugin = ( const tokens = state.tokens for (let i = 0; i < tokens.length; i++) { if (tokens[i].type === 'blockquote_open') { - const open = tokens[i] const startIndex = i - while (tokens[i]?.type !== 'blockquote_close' && i <= tokens.length) - i += 1 - const close = tokens[i] - const endIndex = i + const open = tokens[startIndex] + let endIndex = i + 1 + while ( + !( + tokens[endIndex].type === 'blockquote_close' && + tokens[endIndex].level === open.level + ) && + endIndex < tokens.length + ) + endIndex++ + if (endIndex === tokens.length) continue + const close = tokens[endIndex] const firstContent = tokens .slice(startIndex, endIndex + 1) .find((token) => token.type === 'inline')