Skip to content

Commit

Permalink
refactor: provides a standard interface to get markdown-it (#750)
Browse files Browse the repository at this point in the history
* refactor: provides a standard interface to get markdown-it

* fix: fix eslint
  • Loading branch information
jiawulin001 authored Dec 16, 2021
1 parent 35b02c3 commit e48e75e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 1 addition & 3 deletions doc/cn/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
```javascript
import {mavonEditor} from 'mavon-editor'
mavonEditor.getMarkdownIt()
或者
mavonEditor.mixins[0].data().markdownIt
```

#### 方法3 通过mavonEditor的实例获取
Expand Down Expand Up @@ -58,7 +56,7 @@ export default {
},
computed: {
rawHtml: function() {
return mavonEditor.mixins[0].data().markdownIt.render(this.markdown);
return mavonEditor.getMarkdownIt().render(this.markdown);
}
},
};
Expand Down
4 changes: 1 addition & 3 deletions doc/en/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
```javascript
import {mavonEditor} from 'mavon-editor'
mavonEditor.getMarkdownIt()
or
mavonEditor.mixins[0].data().s_markdown
```

#### method 3: Use mavonEditor ref
Expand Down Expand Up @@ -58,7 +56,7 @@ export default {
},
computed: {
rawHtml: function() {
return mavonEditor.mixins[0].data().markdownIt.render(this.markdown);
return mavonEditor.getMarkdownIt().render(this.markdown);
}
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/dev/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<div>
<App v-if="viewIndex == 1"></App>
<Editor v-if="viewIndex == 2"></Editor>
<Editor v-else-if="viewIndex == 2"></Editor>
</div>
</div>
</template>
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mixins/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var hljs_opts = {
}
};

function initMarkdown() {
export function initMarkdown() {
const markdown = new MarkdownIt(markdown_config);

// add target="_blank" to all link
Expand Down
9 changes: 6 additions & 3 deletions src/mavon-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e48e75e

Please sign in to comment.