var testEdiadtor;
$(function () {
testEditor = editormd("test-editormd", {
width: "90%",
height: 640,
syncScrolling: "single",
path: "../../static/editor.md/lib/",
saveHTMLToTextarea: true,
fullscreen: true,
tex: true, // 开启科学公式TeX语言支持,默认关闭
flowChart: true, // 开启流程图支持,默认关闭
sequenceDiagram: true, // 开启时序/序列图支持,默认关闭,
//dialogLockScreen : false, // 设置弹出层对话框不锁屏,全局通用,默认为true
//dialogShowMask : false, // 设置弹出层对话框显示透明遮罩层,全局通用,默认为true
//dialogDraggable : false, // 设置弹出层对话框不可拖动,全局通用,默认为true
//dialogMaskOpacity : 0.4, // 设置透明遮罩层的透明度,全局通用,默认值为0.1
//dialogMaskBgColor : "#000", // 设置透明遮罩层的背景颜色,全局通用,默认为#fff
//dialogMaskBgColor : "#000", // 设置透明遮罩层的背景颜色,全局通用,默认为#fff
imageUpload: true,
imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL: "/editor/upload/?action=" + "uploadimage",//这里上传的图片接口
onload: function () {
console.log('onload', this);
this.watch().fullscreen();
this.width("100%");
this.height(640);
this.resize("100%", 640);
},
toolbarIcons: function () {
// Or return editormd.toolbarModes[name]; // full, simple, mini
// Using "||" set icons align right.
// return ["undo", "redo", "|", "bold", "hr", "|", "preview", "watch", "|", "fullscreen", "info", "testIcon", "editorIcon", "file", "faicon", "||", "watch", "fullscreen", "preview", "testIcon"]
// return editormd.toolbarModes["full"]
//完整工具栏
//t.toolbarModes={full:["undo","redo","|","bold","del","italic","quote","ucwords","uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","link","reference-link","image","code","preformatted-text","code-block","table","datetime","emoji","html-entities","pagebreak","|","goto-line","watch","preview","fullscreen","clear","search","|","help","info"],simple:["undo","redo","|","bold","del","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","watch","preview","fullscreen","|","help","info"],mini:["undo","redo","|","watch","preview","|","help","info"]}
//需要将自定义图标放入进来
return ["undo", "redo", "|", "bold", "del", "italic", "quote", "ucwords", "uppercase", "lowercase", "|", "h1", "h2", "h3", "h4", "h5", "h6", "|", "list-ul", "list-ol", "hr", "|", "link", "reference-link", "image", "code", "code-block", "table", "datetime", "emoji", "html-entities", "pagebreak", "|", "goto-line", "watch", "preview", "clear", "search", "||", "help", "info", "editorIcon", "returnIcon", "file", "faicon",]
},
//设置图标文本信息
toolbarIconTexts: {
editorIcon: "<span style=\"font-family: 华文楷体\">提交</span>", // 如果没有图标,则可以这样直接插入内容,可以是字符串或HTML标签
returnIcon: "<span style=\"font-family: 华文楷体\">返回</span>" // 如果没有图标,则可以这样直接插入内容,可以是字符串或HTML标签
},
// 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标
toolbarCustomIcons: {
faicon: "<i class=" + "fa fa-star" + 'onclick="alert(' + "'faicon'" + ')";></i>'
},
// 自定义工具栏按钮的事件处理
toolbarHandlers: {
/**
* @param {Object} cm CodeMirror对象
* @param {Object} icon 图标按钮jQuery元素对象
* @param {Object} cursor CodeMirror的光标对象,可获取光标所在行和位置
* @param {String} selection 编辑器选中的文本
*/
editorIcon: function (cm, icon, cursor, selection) {
alert(testEditor.getHTML())
},
returnIcon: function (cm, icon, cursor, selection) {
window.location.href = "/"
}
},
//提示信息
lang: {
toolbar: {
editorIcon: "提交编辑内容",
returnIcon: "返回主页",
undo: "撤销 (Ctrl+Z)"
}
},
});
$("#submit-btn").click(function (event) {
event.preventDefault();
alert(testEditor.getHTML())
testEditor.getMarkdown(); // 获取 Markdown 源码
testEditor.getHTML(); // 获取 Textarea 保存的 HTML 源码
testEditor.getPreviewedHTML(); // 获取预览窗口里的 HTML,在开启 watch 且没有开启 saveHTMLToTextarea 时使用
})
});
// testEditor.gotoLine(90);//转到第90行
//
// testEditor.show();//显示编辑器
//
// testEditor.hide();//隐藏编辑器
//
// alert(testEditor.getMarkdown());//获取编辑器内容(不含html)
//
// alert(testEditor.getHTML());//获取编辑器html内容
//
// testEditor.watch();//开启双窗口对比
//
// testEditor.unwatch();//取消双窗口对比
//
// testEditor.previewing();//预览效果
//
// testEditor.fullscreen();//全屏(按ESC取消)
//
// testEditor.showToolbar();//显示工具栏
//
// testEditor.hideToolbar();//隐藏工具栏