/*
* Editor.md
* @file editormd.js
* @version v1.1.9
* @description A simple online markdown editor.
* @license MIT License
* @author Pandao
* {@link https://github.com/pandao/editor.md}
* @updateTime 2015-03-04
*/
/**
* @fileOverview Editor.md
* @author pandao
* @version 1.1.9
*/
;(function(factory) {
"use strict";
// CommonJS/Node.js
if (typeof require === "function" && typeof exports === "object" && typeof module === "object")
{
module.exports = factory();
}
else if (typeof define === "function") // AMD/CMD/Sea.js
{
define(["jquery"], factory);
}
else
{
window.editormd = factory();
}
}(function() {
/**
* editormd
*
* @param {String} id 编辑器的ID
* @param {Object} options 配置选项 Key/Value
* @returns {Object} editormd 返回editormd对象
*/
"use strict";
var $ = (typeof (jQuery) !== "undefined") ? jQuery : Zepto;
if (typeof ($) === "undefined") {
return ;
}
var editormd = function (id, options) {
return new editormd.fn.init(id, options);
};
editormd.title = editormd.$name = "Editor.md";
editormd.version = "1.1.9";
editormd.homePage = "https://pandao.github.io/editor.md/";
editormd.classPrefix = "editormd-";
editormd.defaults = {
mode : "gfm", //gfm or markdown
markdown : "",
width : "100%",
height : "100%",
path : "./lib/",
watch : true,
placeholder : "now coding markdown...",
readOnly : false,
lineNumbers : true,
matchWordHighlight : true, // options: true, false, "onselected"
styleActiveLine : true, // Highlight the current line
dialogLockScreen : true,
dialogShowMask : true,
dialogDraggable : true,
dialogMaskBgColor : "#fff",
dialogMaskOpacity : 0.1,
onload : function() {},
onchange : function() {},
onfullscreen : function() {},
onfullscreenExit : function() {},
imageUpload : false,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "",
crossDomainUpload : false,
uploadCallbackURL : "",
saveHTMLToTextarea : false,
toc : true,
tocStartLevel : 1, // Said from H1 to create ToC
fontSize : "13px",
htmlDecode : false, // Open the HTML tag identification
tex : false,
flowChart : false, // flowChart.js only support IE9+
sequenceDiagram : false, // sequenceDiagram.js only support IE9+
previewCodeHighlight : true,
inRequirejs : false,
toolbar : true,
toolbarIcons : function() {
return [
"undo", "redo", "|",
"bold", "del", "italic", "quote", "|",
"h1", "h2", "h3", "h4", "h5", "h6", "|",
"list-ul", "list-ol", "hr", "|",
"link", "anchor", "image", "code", "code-block-tab", "code-block", "datetime", "|",
"watch", "preview", "fullscreen", "clear", "|",
"info"
]
},
toolbarTitles : {},
toolbarHandlers : {},
toolbarIconsClass : {
undo : "fa-undo",
redo : "fa-repeat",
bold : "fa-bold",
del : "fa-strikethrough",
italic : "fa-italic",
quote : "fa-quote-left",
h1 : editormd.classPrefix + "bold",
h2 : editormd.classPrefix + "bold",
h3 : editormd.classPrefix + "bold",
h4 : editormd.classPrefix + "bold",
h5 : editormd.classPrefix + "bold",
h6 : editormd.classPrefix + "bold",
"list-ul" : "fa-list-ul",
"list-ol" : "fa-list-ol",
hr : "fa-minus",
link : "fa-link",
anchor : "fa-anchor",
image : "fa-picture-o",
code : "fa-code",
"code-block-tab" : "fa-file-code-o",
"code-block" : "fa-file-code-o",
datetime : "fa-clock-o",
watch : "fa-eye-slash",
unwatch : "fa-eye",
preview : "fa-search",
fullscreen : "fa-arrows-alt",
clear : "fa-eraser",
info : "fa-info-circle"
},
toolbarIconTexts : {},
lang : {
name : "zh-cn",
description : "开源在线Markdown编辑器
A simple markdown doucment online editor.",
toolbar : {
undo : "撤销(Ctrl+Z)",
redo : "重做(Ctrl+Y)",
bold : "粗体",
del : "删除线",
italic : "斜体",
quote : "引用",
h1 : "标题1",
h2 : "标题2",
h3 : "标题3",
h4 : "标题4",
h5 : "标题5",
h6 : "标题6",
"list-ul" : "无序列表",
"list-ol" : "有序列表",
hr : "横线",
link : "链接",
anchor : "锚点",
image : "图片",
code : "行内代码",
"code-block-tab" : "预格式文本 / 代码块(缩进风格)",
"code-block" : "代码块(多语言风格)",
datetime : "日期时间",
watch : "关闭实时预览",
unwatch : "开启实时预览",
preview : "全窗口预览HTML(可按ESC还原)",
fullscreen : "全屏(按ESC还原)",
clear : "清空",
info : "关于" + editormd.title
},
buttons : {
enter : "确定",
cancel : "取消"
},
dialog : {
link : {
title : "添加链接",
url : "链接地址",
urlTitle : "链接标题",
urlEmpty : "错误:请填写链接地址。",
titleEmpty : "错误:请填写链接标题。"
},
anchor : {
title : "添加锚点链接",
name : "锚点名称",
url : "链接地址",
urlTitle : "链接标题",
nameEmpty: "错误:锚点名称不能为空。",
titleEmpty : "错误:请填写锚点链接标题。",
urlEmpty : "错误:请填写锚点链接地址。"
},
image : {
title : "添加图片",
url : "图片地址",
link : "图片链接",
alt : "图片描述",
uploadButton : "本地上传",
imageURLEmpty : "错误:图片地址不能为空。",
uploadFileEmpty : "错误:上传的图片不能为空。",
formatNotAllowed : "错误:只允许上传图片文件,允许上传的图片文件格式有:"
},
tabCodeBlock : {
title : "添加预格式文本或代码块",
codeEmptyAlert : "错误:请填写预格式文本或代码的内容。"
},
codeBlock : {
title : "添加代码块",
selectLabel : "代码语言:",
selectDefaultText : "请选择代码语言",
otherLanguage : "其他语言",
unselectedLanguageAlert : "错误:请选择代码所属的语言类型。",
codeEmptyAlert : "错误:请填写代码内容。"
}
}
}
};
editormd.classNames = {
tex : editormd.classPrefix + "tex"
};
editormd.dialogZindex = 99999;
editormd.$katex = null;
editormd.$marked = null;
editormd.$CodeMirror = null;
editormd.$prettyPrint = null;
editormd.prototype = editormd.fn = {
state : {
watching : false,
loaded : false,
preview : false,
fullscreen : false
},
/**
* 构造函数/实例初始化
* @param {String} id 编辑器的ID
* @param {Object} [options={}] 配置选项 Key/Value
* @returns {editormd} 返回editormd的实例对象
*/
init : function (id, options) {
options = options || {};
var _this = this;
var classPrefix = this.classPrefix = editormd.classPrefix;
var editor = this.editor = $("#" + id);
var settings = this.settings = $.extend(true, editormd.defaults, options);
this.id = id;
this.lang = settings.lang;
var classNames = this.classNames = {
textarea : {
html : this.classPrefix + "html-textarea",
markdown : this.classPrefix + "markdown-textarea"
}
};
this.state.watching = (settings.watch) ? true : false;
if (!editor.hasClass("editormd")) {
editor.addClass("editormd");
}
editor.css({
width : (typeof settings.width === "number") ? settings.width + "px" : settings.width,
height : (typeof settings.height === "number") ? settings.height + "px" : settings.height
});
var markdownTextarea = this.markdownTextarea = editor.children("textarea");
if (markdownTextarea.length < 1)
{
editor.append("");
markdownTextarea = this.markdownTextarea = editor.children("textarea");
}
markdownTextarea.addClass(classNames.textarea.markdown).attr("name", id + "-markdown-doc").attr("placeholder", settings.placeholder);
var appendElements = [
(!settings.readOnly) ? "" : "",
( (settings.saveHTMLToTextarea) ? "" : "" ),
"