diff --git a/doc/cn/markdown.md b/doc/cn/markdown.md index 44b70fa8d..bb7e09939 100644 --- a/doc/cn/markdown.md +++ b/doc/cn/markdown.md @@ -14,8 +14,6 @@ ```javascript import {mavonEditor} from 'mavon-editor' mavonEditor.getMarkdownIt() - 或者 - mavonEditor.mixins[0].data().markdownIt ``` #### 方法3 通过mavonEditor的实例获取 @@ -58,7 +56,7 @@ export default { }, computed: { rawHtml: function() { - return mavonEditor.mixins[0].data().markdownIt.render(this.markdown); + return mavonEditor.getMarkdownIt().render(this.markdown); } }, }; diff --git a/doc/en/markdown.md b/doc/en/markdown.md index dc4ef151e..f01dccfbc 100644 --- a/doc/en/markdown.md +++ b/doc/en/markdown.md @@ -14,8 +14,6 @@ ```javascript import {mavonEditor} from 'mavon-editor' mavonEditor.getMarkdownIt() - or - mavonEditor.mixins[0].data().s_markdown ``` #### method 3: Use mavonEditor ref @@ -58,7 +56,7 @@ export default { }, computed: { rawHtml: function() { - return mavonEditor.mixins[0].data().markdownIt.render(this.markdown); + return mavonEditor.getMarkdownIt().render(this.markdown); } }, }; diff --git a/src/dev/demo.vue b/src/dev/demo.vue index fcfed4a34..fa5e04624 100644 --- a/src/dev/demo.vue +++ b/src/dev/demo.vue @@ -6,7 +6,7 @@
- +
diff --git a/src/index.js b/src/index.js index 69ed6b587..166af5e7d 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,10 @@ */ const mavonEditor = require('./mavon-editor.vue'); const VueMavonEditor = { + /** + * @deprecated + * @see mavonEditor.getMarkdownIt() + */ markdownIt: mavonEditor.mixins[0].data().markdownIt, mavonEditor: mavonEditor, LeftToolbar: require('./components/md-toolbar-left'), diff --git a/src/lib/mixins/markdown.js b/src/lib/mixins/markdown.js index 63f1d3b20..6570a7485 100644 --- a/src/lib/mixins/markdown.js +++ b/src/lib/mixins/markdown.js @@ -55,7 +55,7 @@ var hljs_opts = { } }; -function initMarkdown() { +export function initMarkdown() { const markdown = new MarkdownIt(markdown_config); // add target="_blank" to all link diff --git a/src/mavon-editor.vue b/src/mavon-editor.vue index 52c3f0cb7..9d4a92c3e 100644 --- a/src/mavon-editor.vue +++ b/src/mavon-editor.vue @@ -113,8 +113,7 @@ import {stopEvent} from './lib/util.js' import {toolbar_left_click, toolbar_left_addlink} from './lib/toolbar_left_click.js' import {toolbar_right_click} from './lib/toolbar_right_click.js' import {CONFIG} from './lib/config.js' -import markdown from './lib/mixins/markdown.js' - +import markdown, {initMarkdown} from './lib/mixins/markdown.js' import md_toolbar_left from './components/md-toolbar-left.vue' import md_toolbar_right from './components/md-toolbar-right.vue' import "./lib/font/css/fontello.css" @@ -360,7 +359,11 @@ export default { document.body.removeChild(this.$refs.help); }, getMarkdownIt() { - return this.mixins[0].data().markdownIt + let mdIt = this.mixins[0].data().markdownIt; + if (!mdIt) { + mdIt = initMarkdown(); + } + return mdIt }, methods: { loadExternalLink(name, type, callback) {