diff --git a/src/node/markdown/plugins/githubAlerts.ts b/src/node/markdown/plugins/githubAlerts.ts index 238cf98f..fd084f59 100644 --- a/src/node/markdown/plugins/githubAlerts.ts +++ b/src/node/markdown/plugins/githubAlerts.ts @@ -1,6 +1,9 @@ import type MarkdownIt from 'markdown-it' import type { ContainerOptions } from './containers' +const markerRE = + /^\[\!(TIP|NOTE|INFO|IMPORTANT|WARNING|CAUTION|DANGER)\]([^\n\r]*)/i + export const gitHubAlertsPlugin = ( md: MarkdownIt, options?: ContainerOptions @@ -15,9 +18,6 @@ export const gitHubAlertsPlugin = ( danger: options?.dangerLabel || 'DANGER' } as Record - const RE = - /^\[\!(TIP|NOTE|INFO|IMPORTANT|WARNING|CAUTION|DANGER)\]([^\n\r]*)/i - md.core.ruler.after('block', 'github-alerts', (state) => { const tokens = state.tokens for (let i = 0; i < tokens.length; i++) { @@ -32,7 +32,7 @@ export const gitHubAlertsPlugin = ( .slice(startIndex, endIndex + 1) .find((token) => token.type === 'inline') if (!firstContent) continue - const match = firstContent.content.match(RE) + const match = firstContent.content.match(markerRE) if (!match) continue const type = match[1].toLowerCase() const title = match[2].trim() || titleMark[type] || capitalize(type)