ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## Markdown编辑器 内部使用 [editor.md](https://pandao.github.io/editor.md/) 开源编辑器实现。 [TOC] ## 使用方法 ![](https://box.kancloud.cn/fde79123a61cceb282225aed790c413c_1406x734.png) ~~~ <div id="editormd"><textarea name="content" hidden>初始内容</textarea></div> <script> require(['hdjs'], function (hdjs) { hdjs.markdown("editormd", { width: '100%', heigth: 300, callback:function(editormd){ //编辑器对象 console.log(editormd); } }); }); </script> ~~~ 第二个参数是选项,可以根据需要自行设置其他选项 ## 显示内容 ~~~ <script> require(['hdjs', 'marked', 'highlight'], function (hdjs, marked) { marked.setOptions({ renderer: new marked.Renderer(), highlight: function (code) { return hljs.highlightAuto(code).value; }, pedantic: true, gfm: true, tables: true, breaks: false, sanitize: false, smartLists: true, smartypants: false, xhtml: false }); $('.markdown').each(function (i, md) { $(md).html($.trim(marked($(md).find('textarea').val()))); }) hljs.initHighlightingOnLoad(); }) </script> ~~~ 如果不能正常解析参考以下代码(去除行首空白): ~~~ <div class="markdown"> <textarea hidden>{{ preg_replace('@(^\s*)@m','',$hdcms['content']) }}</textarea> </div> ~~~ 第三个参数为内容变量 ## 替换内容 ~~~ editormd.setSelection({line:0, ch:0}, {line:9999, ch:9999}); editormd.replaceSelection(""); ~~~ editormd为编辑器对象,需要在callback中获得