Skip to content

Commit 7e728a7

Browse files
committed
feat(plugin): add align plugin
1 parent be87a7c commit 7e728a7

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

dev/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import '@/plugins/copy-code/copy-code';
3030
import createHighLinesPlugin from '@/plugins/highlight-lines/';
3131
import '@/plugins/highlight-lines/highlight-lines';
3232
import createMermaidPlugin from '@/plugins/mermaid/cdn';
33+
import createAlignPlugin from '@/plugins/align';
3334

3435
import vuepressTheme from '@/theme/vuepress';
3536
import enUS from '@/lang/en-US';
@@ -43,7 +44,8 @@ VueMarkdownEditor.use(createEmojiPlugin())
4344
.use(createLineNumberPlugin())
4445
.use(createCopyCodePlugin())
4546
.use(createHighLinesPlugin())
46-
.use(createMermaidPlugin());
47+
.use(createMermaidPlugin())
48+
.use(createAlignPlugin());
4749

4850
// VueMarkdownEditor.use(githubTheme, {
4951
// codeHighlightExtensionMap: {

src/plugins/align/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import markdownItContainer from '@/utils/markdown-it-container';
2+
3+
const extendMarkdown = function (mdParser) {
4+
if (mdParser) {
5+
markdownItContainer(mdParser, {
6+
type: 'align-left',
7+
defaultTitle: '',
8+
before: (info) => `<div align="left">${info || ''}\n`,
9+
after: () => '</div>\n',
10+
});
11+
12+
markdownItContainer(mdParser, {
13+
type: 'align-center',
14+
defaultTitle: '',
15+
before: (info) => `<div align="center">${info || ''}\n`,
16+
after: () => '</div>\n',
17+
});
18+
19+
markdownItContainer(mdParser, {
20+
type: 'align-right',
21+
defaultTitle: '',
22+
before: (info) => `<div align="right">${info || ''}\n`,
23+
after: () => '</div>\n',
24+
});
25+
}
26+
};
27+
28+
export default function () {
29+
return {
30+
install(VMdEditor) {
31+
VMdEditor.extendMarkdown(extendMarkdown);
32+
},
33+
};
34+
}

0 commit comments

Comments
 (0)