layui/example/src/plugin/create-quote.ts

29 lines
703 B
TypeScript
Raw Normal View History

2021-09-26 22:09:33 +00:00
import container from 'markdown-it-container'
import type Token from 'markdown-it/lib/token'
type ContainerArgs = [
2021-12-30 06:00:25 +00:00
typeof container, string,
{ render(tokens: Token[], idx: number): string }
2021-09-26 22:09:33 +00:00
]
export default function createContainer(
klass: string,
defaultTitle: string
): ContainerArgs {
return [
container,
klass,
{
render(tokens, idx) {
const token = tokens[idx]
const info = token.info.trim().slice(klass.length).trim()
if (token.nesting === 1) {
2022-02-11 10:28:35 +00:00
return `<lay-quote style="margin-left:0px;margin-right:0px;margin-top:20px;margin-bottom:40px;">${info}`
2021-09-26 22:09:33 +00:00
} else {
2022-02-11 10:28:35 +00:00
return '</lay-quote>\n'
2021-09-26 22:09:33 +00:00
}
},
},
]
2021-10-25 17:14:17 +00:00
}