例子:https://pandao.github.io/editor.md/examples/index.html
所有的参数:https://github.com/pandao/editor.md
{
mode: "gfm", // gfm or markdown
name: "", // Form element name for post
value: "", // value for CodeMirror, if mode not gfm/markdown
/**设置主题颜色,与函数共同作用:setTheme(theme),setCodeMirrorTheme(theme)||setEditorTheme(theme),setPreviewTheme(theme)*/
theme: "", // 工具栏的主题(default,dark)。Editor.md self themes, before v1.5.0 is CodeMirror theme, default empty
editorTheme: "default", // 编辑栏的主题(default,dark等很多中)。 Editor area, this is CodeMirror theme at v1.5.0
previewTheme: "", // 预览栏的主题(default,dark)。 Preview area theme, default empty
markdown: "", // 编辑栏默认内容。也可以直接放在textarea内。Markdown source code
appendMarkdown: "", // 在markdown后面追加的内容。 if in init textarea value not empty, append markdown to textarea
width: "100%", // w可以为数值也可以为百分比
height: "100%", // h可以为数值也可以为百分比
autoHeight: false, // 自适应h
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, // 编辑栏有折叠按钮(true)。
autoFocus: true, // Enable / disable auto focus editor left input area
autoCloseTags: true,
searchReplace: true, // 是否启动搜索功能;ctrl+f;Enable / disable (CodeMirror) search and replace function
syncScrolling: true, // 是否一起滚动(false的时候互不影响;single的时候,左影响右,右不影响左;true的时候,互相影响;) options: true | false | "single", default true
readOnly: false, // 还是左右两部分,只是左部分不能编辑了。 Enable / disable readonly mode
tabSize: 4,
indentUnit: 4,
lineNumbers: true, // 左侧编辑部分,是否显示行数。 Display editor line numbers
lineWrapping: true,
autoCloseBrackets: true,
showTrailingSpace: true,
matchBrackets: true,
indentWithTabs: true,
styleSelectedText: true,
matchWordHighlight: true, // options: true, false, "onselected"
styleActiveLine: true, // 左边编辑部分,当前行高亮。Highlight the current line
dialogLockScreen: true, //设置弹出层对话框不锁屏,全局通用,默认为true
dialogShowMask: true, //设置弹出层对话框显示透明遮罩层,全局通用,默认为true
dialogDraggable: true, //设置弹出层对话框不可拖动,全局通用,默认为true
dialogMaskBgColor: "#fff", //设置透明遮罩层的背景颜色,全局通用,默认为#fff
dialogMaskOpacity: 0.1, //设置透明遮罩层的透明度,全局通用,默认值为0.1
fontSize: "13px",
saveHTMLToTextarea: false, // ????。 If enable, Editor will create a <textarea name="{editor-id}-html-code"> tag save HTML code for form post to server-side.
disabledKeyMaps: [],
onload: function () {
//console.log('onload', this);
//this.fullscreen();
//this.unwatch();
//this.watch().fullscreen();
//this.width("100%");
//this.height(480);
//this.resize("100%", 640);
},
onresize: function () {
},
onchange: function () {
},
onwatch: null,
onunwatch: null,
onpreviewing: function () {
},
onpreviewed: function () {
},
onfullscreen: function () {
},
onfullscreenExit: function () {
},
onscroll: function () {
},
onpreviewscroll: function () {
},
imageUpload: false, // Enable/disable upload
imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL: "", // Upload url
crossDomainUpload: false, // Enable/disable Cross-domain upload
uploadCallbackURL: "", // Cross-domain upload callback url
toc: true, // Table of contents
tocm: false, // Using [TOCM], auto create ToC dropdown menu
tocTitle: "", // for ToC dropdown menu button
tocDropdown: false, // Enable/disable Table Of Contents dropdown menu
tocContainer: "", // Custom Table Of Contents Container Selector
tocStartLevel: 1, // Said from H1 to create ToC
htmlDecode: false, // "style,script,iframe|on*", // 开启 HTML 标签解析,为了安全性,默认不开启。 Open the HTML tag identification
pageBreak: true, // Enable parse page break [========]
atLink: true, // for @link
emailLink: true, // for email address auto link
taskList: false, // 是否启用checkbox功能。 Enable Github Flavored Markdown task lists
emoji: false, // :emoji: , Support Github emoji, Twitter Emoji (Twemoji);
// Support FontAwesome icon emoji :fa-xxx: > Using fontAwesome icon web fonts;
// Support Editor.md logo icon emoji :editormd-logo: :editormd-logo-1x: > 1~8x;
tex: false, // TeX(LaTeX), based on KaTeX,开启科学公式TeX语言支持,默认关闭
flowChart: false, // flowChart.js only support IE9+,开启流程图支持,默认关闭
sequenceDiagram: false, // sequenceDiagram.js only support IE9+,开启时序/序列图支持,默认关闭
previewCodeHighlight: true, // 关闭预览 HTML 的代码块高亮,默认开启。Enable / disable code highlight of editor preview area
/****************************************工具栏*********************************************/
toolbar: true, // 是否显示工具栏。 show or hide toolbar
// 可以与函数setToolbarAutoFixed共同作用。
toolbarAutoFixed: true, // window滚动的时候,工具栏是否固定位置(excel冻结窗格的样子)。on window scroll auto fixed position
// 工具栏显示多少个按钮
// toolbarIcons: "full", // 工具栏的模式(simple,full,mimi),也可以是函数(自定义)。 Toolbar icons mode, options: full, simple, mini, See `editormd.toolbarModes` property.
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", "testIcon2", "file", "faicon", "||", "watch", "fullscreen", "preview", "testIcon",
},
toolbarTitles: {},
// 自定义工具栏按钮的事件处理
toolbarHandlers: {
ucwords: function () {
return editormd.toolbarHandlers.ucwords;
},
lowercase: function () {
return editormd.toolbarHandlers.lowercase;
}
},
// 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标
toolbarCustomIcons: { // using html tag create toolbar icon, unused default <a> tag.
lowercase: "<a href=\"javascript:;\" title=\"Lowercase\" unselectable=\"on\"><i class=\"fa\" name=\"lowercase\" style=\"font-size:24px;margin-top: -10px;\">a</i></a>",
"ucwords": "<a href=\"javascript:;\" title=\"ucwords\" unselectable=\"on\"><i class=\"fa\" name=\"ucwords\" style=\"font-size:20px;margin-top: -3px;\">Aa</i></a>",
'ksbk2': '<i class="fa fa-camera-retro" onclick="alert(\'ksbk2\');"></i>', // 需要把名称添加在toolbar中
},
// 更改按钮的icon
toolbarIconsClass: {
testIcon: "fa-gears", // 指定一个FontAawsome的图标类
// ksbk:'fa-camera-retro', // 自定义的按钮的icon,如果没有icon的话,那么显示toolbarIconTexts的汉字。
},
// 如果没有icon,那么显示的文字
toolbarIconTexts: {
testIcon2: "测试按钮Test button", // 如果没有图标,则可以这样直接插入内容,可以是字符串或HTML标签
ksbk: '开水没有春天',
},
lang: { // Language data, you can custom your language.
name: "zh-cn",
description: "开源在线Markdown编辑器<br/>Open source online Markdown editor.",
tocTitle: "目录",
toolbar: {
undo: "ksbk", // icon的title属性(hover的时候,提示内容)
redo: '开水没有春天',
// 可以自定义工具栏的,eg:ksbk
ksbk: '我是春天',
},
button: {
//...
},
dialog: {
//...
}
//...
},
onload: function () {
console.log('onload', this); // 从this的property中查看它的所有方法。
// 也可以执行下面的函数
// this.fullscreen(); // 全屏
// this.unwatch(); // 只有编辑
// this.unwatch().fullscreen(); // 只有编辑且全屏,支持链式
// this.setMarkdown("#PHP"); // 设置值
// this.width("100%"); // w
// this.height(480); // h
// this.resize("100%", 640); // 设置w和h
}
方法:
watch:左右两侧都有。
unwatch:只有左侧编辑部分。
与属性watch一起作用:watch:false
,那么只有左边编辑部分,没有预览部分。
gotoLine:跳转到某一行。参数:
testEditor.gotoLine(300);
testEditor.gotoLine("first");
// or
//testEditor.gotoLine(1);
testEditor.gotoLine("last");
// or
//testEditor.gotoLine(testEditor.cm.lineCount());
show:显示。
hide:隐藏。
getMarkdown:编辑的内容。
getHTML:转换成html的内容。
showToolbar:显示工具栏。
hideToolbar:隐藏工具栏。
fullScreen:全屏
previewing:预览
setToolbarAutoFixed(boolean):设置是否工具栏固定。
配置属性的方法:eg:
testEditor.config("syncScrolling", true);
配置事件:eg:
// resize的时候,执行的事件
this.config("onresize", function() {
console.log("onresize =>", this);
});
识别和解析HTML标签
https://pandao.github.io/editor.md/examples/html-tags-decode.html
包含:标签和属性。eg:
/*所有的**/
htmlDecode : true, // Decode all html tags & attributes
/*部分自定义*/
htmlDecode : "style,script,iframe,sub,sup|on*", // Filter tags, and all on* attributes
htmlDecode : "style,script,iframe,sub,sup|*" // Filter tags, and all attributes
htmlDecode : "style,script,iframe,sub,sup,embed|onclick,title,onmouseover,onmouseout,style" // Filter tags, and your custom attributes