layui/package/document-component/src/plugin/create-quote.ts

27 lines
685 B
TypeScript
Raw Normal View History

2022-04-05 02:31:31 +00:00
import container from "markdown-it-container";
import type Token from "markdown-it/lib/token";
2021-09-26 22:09:33 +00:00
type ContainerArgs = [
2022-04-05 02:31:31 +00:00
typeof container,
string,
2021-12-30 06:00:25 +00:00
{ render(tokens: Token[], idx: number): string }
2022-04-05 02:31:31 +00:00
];
2021-09-26 22:09:33 +00:00
export default function createContainer(klass: string): ContainerArgs {
2021-09-26 22:09:33 +00:00
return [
container,
klass,
{
render(tokens, idx) {
2022-04-05 02:31:31 +00:00
const token = tokens[idx];
const info = token.info.trim().slice(klass.length).trim();
2021-09-26 22:09:33 +00:00
if (token.nesting === 1) {
2022-04-05 02:31:31 +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-04-05 02:31:31 +00:00
return "</lay-quote>\n";
2021-09-26 22:09:33 +00:00
}
},
},
2022-04-05 02:31:31 +00:00
];
2021-10-25 17:14:17 +00:00
}