@ -3,40 +3,17 @@ import container from 'markdown-it-container'
import type { RenderRule } from 'markdown-it/lib/renderer.mjs'
import type { RenderRule } from 'markdown-it/lib/renderer.mjs'
import type Token from 'markdown-it/lib/token.mjs'
import type Token from 'markdown-it/lib/token.mjs'
import type { MarkdownEnv } from '../../shared'
import type { MarkdownEnv } from '../../shared'
import {
import { extractTitle } from './preWrapper'
extractTitle ,
getAdaptiveThemeMarker ,
type Options
} from './preWrapper'
export const containerPlugin = (
export const containerPlugin = (
md : MarkdownItAsync ,
md : MarkdownItAsync ,
options : Options ,
options? : ContainerOptions
containerOptions? : ContainerOptions
) = > {
) = > {
md . use ( . . . createContainer ( 'tip' , containerOptions ? . tipLabel || 'TIP' , md ) )
md . use ( . . . createContainer ( 'tip' , options ? . tipLabel || 'TIP' , md ) )
. use ( . . . createContainer ( 'info' , containerOptions ? . infoLabel || 'INFO' , md ) )
. use ( . . . createContainer ( 'info' , options ? . infoLabel || 'INFO' , md ) )
. use (
. use ( . . . createContainer ( 'warning' , options ? . warningLabel || 'WARNING' , md ) )
. . . createContainer (
. use ( . . . createContainer ( 'danger' , options ? . dangerLabel || 'DANGER' , md ) )
'warning' ,
. use ( . . . createContainer ( 'details' , options ? . detailsLabel || 'Details' , md ) )
containerOptions ? . warningLabel || 'WARNING' ,
md
)
)
. use (
. . . createContainer (
'danger' ,
containerOptions ? . dangerLabel || 'DANGER' ,
md
)
)
. use (
. . . createContainer (
'details' ,
containerOptions ? . detailsLabel || 'Details' ,
md
)
)
// explicitly escape Vue syntax
// explicitly escape Vue syntax
. use ( container , 'v-pre' , {
. use ( container , 'v-pre' , {
render : ( tokens : Token [ ] , idx : number ) = >
render : ( tokens : Token [ ] , idx : number ) = >
@ -46,7 +23,7 @@ export const containerPlugin = (
render : ( tokens : Token [ ] , idx : number ) = >
render : ( tokens : Token [ ] , idx : number ) = >
tokens [ idx ] . nesting === 1 ? ` <div class="vp-raw"> \ n ` : ` </div> \ n `
tokens [ idx ] . nesting === 1 ? ` <div class="vp-raw"> \ n ` : ` </div> \ n `
} )
} )
. use ( . . . createCodeGroup ( options, md) )
. use ( . . . createCodeGroup ( md) )
}
}
type ContainerArgs = [ typeof container , string , { render : RenderRule } ]
type ContainerArgs = [ typeof container , string , { render : RenderRule } ]
@ -80,7 +57,7 @@ function createContainer(
]
]
}
}
function createCodeGroup ( options: Options , md: MarkdownItAsync ) : ContainerArgs {
function createCodeGroup ( md: MarkdownItAsync ) : ContainerArgs {
return [
return [
container ,
container ,
'code-group' ,
'code-group' ,
@ -118,7 +95,7 @@ function createCodeGroup(options: Options, md: MarkdownItAsync): ContainerArgs {
}
}
}
}
return ` <div class="vp-code-group ${ getAdaptiveThemeMarker ( options ) } "><div class="tabs">${ tabs } </div><div class="blocks"> \ n `
return ` <div class="vp-code-group "><div class="tabs">${ tabs } </div><div class="blocks"> \ n `
}
}
return ` </div></div> \ n `
return ` </div></div> \ n `
}
}