网页中加入markdown编辑器

在浏览器集成 Mditor?

[说明]使用mditor插件可以把markdown文本转化成html

第一步:
引入 Mditor 样式文件

<link rel="stylesheet" href="your-path/dist/css/mditor.min.css" />

引用 Mditor 脚本文件

<script src="your-path/dist/js/mditor.min.js"></script>

当然,也可以使用 CDN 资源

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/css/mditor.min.css" />

<script src="https://unpkg.com/[email protected]/dist/js/mditor.min.js"></script>


第二步:
添加 textarea 元素

<textarea name="editor" id="editor"></textarea>

创建 Mditor 实例

var mditor =  Mditor.fromTextarea(document.getElementById('editor'));

参考地址:https://www.npmjs.com/package/mditor

在node中使用

1.安装

npm i mditor -s

2.导入

 const mditor=require('mditor')

3.在需要渲染的页面中加入

var mditor =  Mditor.fromTextarea(document.getElementById('editor'));

从数据库读出时,可以使用marked方法把markdown文本转化成html

 const html = marked(result[0].content)

猜你喜欢

转载自blog.csdn.net/weixin_42458708/article/details/82697937