pull/3482/head
Divyansh Singh 2 years ago
parent 71c01ec30c
commit 5f245eca7b

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

Loading…
Cancel
Save