不啰嗦看效果
如果觉得对你项目有用请继续深入。
1. editor.md简介
-
1.1 说明
Editor.md 是一款开源的、可嵌入的 Markdown 在线编辑器(组件),基于 CodeMirror、jQuery 和 Marked 构建。
-
1.2 项目地址
github地址:https://github.com/pandao/editor.md
1.3 项目效果图
2. 项目整合
2.1 下载editormd至自己项目根目录
如下为我的项目目录:
2.2 项目部署
引入css样式文件和js文件
注意:
务必引入 editormd/css/editormd.css
和 editormd/editormd.js
两个文件。
页面
textarea
样式
JS调用代码
配置参数
{
theme : "", // Editor.md self themes, before v1.5.0 is CodeMirror theme,
editorTheme : "default", // Editor area, this is CodeMirror theme at v1.5.0
previewTheme : "", // Preview area theme, default empty
width : "100%",
height : "100%",
path : "./lib/", // Dependents module file directory
pluginPath : "", // If this empty, default use settings.path + "../plugins/"
delay : 300, // Delay parse markdown to html, Uint : ms
autoLoadModules : true, // Automatic load dependent module files
watch : true,
placeholder : "Enjoy Markdown! coding now...",
gotoLine : true, // Enable / disable goto a line
codeFold : false,
autoHeight : false,
autoFocus : true, // Enable / disable auto focus editor left input area
autoCloseTags : true,
searchReplace : true, // Enable / disable (CodeMirror) search and replace function
syncScrolling : true, // options: true | false | "single", default true
saveHTMLToTextarea : false, // If enable, Editor will create a
显示效果
-
003.png
界面出来了已经完成很大一部分了。通过设置提交数据打印可以查看editormd提交数据的一个结构
-
005.png
通过debug
我们可有看到提交给后台的数据如下:
-
004.png
3. 图片上传处理
3.1 editormd的图片上传功能有很多坑,下面我们将依次填坑。
editormd图片上传功能需要设置,要在返回固定格式的json数据,即使在调试时候。
扣丁曼
在初次使用editormd项目时在此处浪费了很多时间。开启图片上传参数
imageUpload : true
、imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
、imageUploadURL : "./upload.php",
后台返回样式如下:
{
success : 0 | 1, //0表示上传失败;1表示上传成功
message : "提示的信息",
url : "图片地址" //上传成功时才返回
}
3.2 增加截图上传和拖拽上传图片功能
由于editormd的上传图片功能用户体验并不友好!每次上传图片很费事。
扣丁曼
通过收集网上其他小伙伴提供的建议也实现了editormd的截图上传和拖拽上传功能。
-
新增JS插件代码
文件名
editoemd-image-past.js
放置于editormd/plugins
文件夹下
- 页面引入
- 项目中配置
path : "__PAGE__/global/plugins/editormd/lib/",
imageUploadURL : "/uploadFile", //文件提交请求路径
onload : function() {
initPasteDragImg(this); //配置图片粘贴上传
},
saveHTMLToTextarea : true, //注意3:这个配置,方便post提交表单
4. 前台展示editormd数据
- 在view页面引入css文件和js文件如下
- 页面展示区
- js处理
- 效果图
5. 项目源码
关注公众号“扣丁曼” 回复editormd获取项目源码。
本项目采用php作为处理语言,其他语种小伙伴请各显神通。
6.联系我
通过公众号“扣丁曼”(号码:qcgcoder)直接与我联系。
-
通过我的博客获取最新资讯
博客网址:https://52qcg.cn