前言
自建博客我觉得最痛苦的事就是选用哪个Markdown,找一个符合自己并且集成在里面非常不容易,当前我使用的是editor.md这款,其实非常不错,地址:https://pandao.github.io/editor.md,但是他有几个缺点,让我萌生换一个的想法。
![3020258ccc21fc61aa1b86cdfb7aeead.png](https://i-blog.csdnimg.cn/blog_migrate/67861d7c09d455383c7bc809434edce0.png)
于是闲下时间重新找了一款,那就是tui.editor。tui.editor和editor.md的star都挺高,另外editor.md是国产的。
![573965775e044c7ce5fbc9a723064968.png](https://i-blog.csdnimg.cn/blog_migrate/bb530b22b00bff57f0490df61599896f.png)
![bf29969b0b7fc5b75beea34f1df6d290.png](https://i-blog.csdnimg.cn/blog_migrate/048996e6805a0f4bb8b9541c4781156d.png)
下面将演示tui.editor与Vue集成。
tui.editor与Vue
- 下载
npm install --save @toast-ui/vue-editor
- 新建vue,引入组件。
<div><editor:initialValue="editorText":options="editorOptions"height="500px"initialEditType="wysiwyg"previewStyle="vertical"
/>div>template><script>import "codemirror/lib/codemirror.css";import "@toast-ui/editor/dist/toastui-editor.css";import { Editor } from "@toast-ui/vue-editor";export default {
data() {return {editorText:"#asd"
};
},components: {editor: Editor
},
created() {
},methods: {
}
};script><style lang="less" scoped>style>
![e518ac78da5cfe82385d4d92eb5f51f5.png](https://i-blog.csdnimg.cn/blog_migrate/6a8d7b2b8ecd7805d314690d37820083.png)
- 运行
npm run serve
![96b14ef9fd8af6ebea9f97dfd958493a.png](https://i-blog.csdnimg.cn/blog_migrate/152918f1ebbda64576855a8a90cc3ff0.png)
但是上述缺点是不能代码高亮,如果要代码高亮,需要增加插件,而这种方式引入具体我也不知道怎么设置。
只预览
class="container">
"editor">
效果如下,支持代码高亮。
![c8e5d38116db9b6cd423aefd4aaa96ad.png](https://i-blog.csdnimg.cn/blog_migrate/07d09b04ea516ad1acca2b28eb9bc50f.png)
API
tui.editor提供了非常多个API,可以到https://nhn.github.io/tui.editor/latest/下查看。
![2d63cc02c798ebbe91c889d037b50e80.png](https://i-blog.csdnimg.cn/blog_migrate/6da404d2972134470b88e010c8739ac6.png)
另外代码风格可以到https://github.com/highlightjs/highlight.js/tree/master/src/styles下载,只需要替换如下位置即可
import "highlight.js/styles/{风格}.css";