NoneCMS 使用Markdown编辑器
作者:nango
阅读:2645次
来源:原创
时间:2017-06-19 11:00
NoneCMS 在V1.2.0版本添加了Markdown编辑器,你可以在Ueditor和Markdown之间随意切换。 下面说一下怎么在NoneCMS中使用Markdown: 首先,把你的代码更新为最新的版本,或者下载v1.2.0补丁包进行升级。 然后登录后台管理,在系统设置中可以看到编辑器选择项,选择Markdown选项,点击保存,接下来在文章添加、产品添加、单页内容页面的编辑器都会切换为Markdown。接下来你就可以随意添加内容了,Markdown的语法,具体使用可以参照:http://pandao.github.io/editor.md/ 需要说明的是,这里Markdown编辑的内容,存入数据表中时是存的Markdown格式的字串,并没有转化为html格式;这里也是出于几点考虑: 1:转化为html格式字串会无端占用表空间;一行Markdown格式的代码,可能转化为Html十几行的代码。 2:即便转化为了html格式,在前台展示时,代码依然不能高亮,还需要引入相应js来进行编译 基于以上两点,所以在前台展示Markdown代码时,我们需要引入相应的js并且进行实例化操作;具体如下: ```html <div class="z_con" id="test-editormd-view2"> <h1 align="center">{$content.title}</h1><br/><hr/><br/> <!--使用时将#号去掉--> <#textarea style="display:none;">{$content.content}</#textarea> </div> ``` ```javascript <link rel="stylesheet" href="/static/common/plugin/editor.md/css/editormd.preview.css" /> <script src="/static/common/plugin/editor.md/lib/marked.min.js"></script> <script src="/static/common/plugin/editor.md/lib/prettify.min.js"></script> <script src="/static/common/plugin/editor.md/lib/raphael.min.js"></script> <script src="/static/common/plugin/editor.md/lib/underscore.min.js"></script> <script src="/static/common/plugin/editor.md/lib/sequence-diagram.min.js"></script> <script src="/static/common/plugin/editor.md/lib/flowchart.min.js"></script> <script src="/static/common/plugin/editor.md/lib/jquery.flowchart.min.js"></script> <script src="/static/common/plugin/editor.md/editormd.js"></script> <script type="text/javascript"> testEditormdView2 = editormd.markdownToHTML("test-editormd-view2", { htmlDecode : "style,script,iframe", // you can filter tags decode emoji : true, taskList : true, tex : true, // 默认不解析 flowChart : true, // 默认不解析 sequenceDiagram : true, // 默认不解析 }); </script> ``` 这里的test-editormd-view2,就是包含Markdown语法的标签的id,可以随意起。 这样我们在前台展示的时候,代码就会高亮显示。 > 虽然NoneCMS提供了两种编辑器,但是并不建议同一个项目中来回切换。如果真有需求要来回切换,那么在前台展示时,不是Markdown的内容就不需要引入js来进行实例化输出,这里可以通过flag属性来判断是哪个编辑器编辑的内容:flag=8表示百度富文本框;flag=9表示Markdown。
NANGO
首 页
编程
聊天室
简介:
欢迎大家光临nango的博客,该博客由NoneCms搭建而成。
文章分类
PHP
js
centos
Python
MySQL
Laravel
最新文章
NoneCms 重大bug更新
docker compose编排的php开发环境
NoneCms 基于workerman的聊天室具体使用
centos7 + sendmail + php mail()函数实现邮件发送
文章归档
2018-12 (2)
2018-09 (1)
2018-01 (1)
2017-10 (1)
2017-07 (2)
2017-06 (2)
2017-03 (1)
2017-02 (2)
2017-01 (2)
2016-11 (4)
2016-10 (5)
2016-09 (3)
您的浏览器不支持 canvas.
© Nango
NANGO
文章分类