放到项目中之后 然后引入jq css js
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<link rel="stylesheet" href="/node_modules/editor/css/editormd.css" />
<script src="/node_modules/editor/editormd.min.js"></script>
</head>
<body>
<button id="look">查看源码</button>
<div id="test-editormd">
<textarea></textarea>
</div>
<!--在该div中展示,如有初始化的数据可以放在textarea中-->
<div id="testEditorMdview">
<textarea id="appendTest" style="display:none;"></textarea>
</div>
</body>
<script>
var testEditor;
testEditor = editormd("test-editormd", {
placeholder: '本编辑器支持Markdown编辑,左边编写,右边预览', //默认显示的文字,这里就不解释了
width: "60%",
height: 800,
syncScrolling: "single",
path: "/node_modules/editor/lib/", //你的path路径(原资源文件中lib包在我们项目中所放的位置)
theme: "white",//工具栏主题
previewTheme: "white",//预览主题
editorTheme: "pastel-on-white",//编辑主题
imageUpload: true,
imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL: "{:url('Knowledge/uploadImg')}",//上传图片使用方法
saveHTMLToTextarea: true,
emoji: true,
taskList: true,
tocm: true, // Using [TOCM]
tex: true, // 开启科学公式TeX语言支持,默认关闭
flowChart: true, // 开启流程图支持,默认关闭
sequenceDiagram: true, // 开启时序/序列图支持,默认关闭,
toolbarIcons: function () { //自定义工具栏,后面有详细介绍
return editormd.toolbarModes['full']; // full, simple, mini
},
});
// testEditor.getMarkdown();
// 在js中调用getMarkdown这个方法可以获得Markdown格式的文本。
//点击展示按钮
$("#look").click(function () {
//存储在数据库中即可
var s = testEditor.getMarkdown();
//存储之后如何展示
$("#appendTest").val(s);
var testEditormdView2 = editormd.markdownToHTML("testEditorMdview", {
htmlDecode: "style,script,iframe", // you can filter tags decode
emoji: true,
taskList: true,
tex: true, // 默认不解析
flowChart: true, // 默认不解析
sequenceDiagram: true, // 默认不解析
});
})
</script>
</html>
下边就是展示的效果