",
@@ -1358,30 +1371,30 @@
].join("\n");
editor.append(infoDialogHTML);
-
+
var infoDialog = this.infoDialog = editor.children("." + classPrefix + "dialog-info");
infoDialog.find("." + classPrefix + "dialog-close").bind(editormd.mouseOrTouch("click", "touchend"), function() {
_this.hideInfoDialog();
});
-
+
infoDialog.css("border", (editormd.isIE8) ? "1px solid #ddd" : "").css("z-index", editormd.dialogZindex).show();
-
+
this.infoDialogPosition();
return this;
},
-
+
/**
* 关于Editor.md对话居中定位
* Editor.md dialog position handle
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
infoDialogPosition : function() {
var infoDialog = this.infoDialog;
-
+
var _infoDialogPosition = function() {
infoDialog.css({
top : ($(window).height() - infoDialog.height()) / 2 + "px",
@@ -1392,33 +1405,33 @@
_infoDialogPosition();
$(window).resize(_infoDialogPosition);
-
+
return this;
},
-
+
/**
* 显示关于Editor.md
* Display about Editor.md dialog
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
showInfoDialog : function() {
$("html,body").css("overflow-x", "hidden");
-
+
var _this = this;
var editor = this.editor;
- var settings = this.settings;
+ var settings = this.settings;
var infoDialog = this.infoDialog = editor.children("." + this.classPrefix + "dialog-info");
-
+
if (infoDialog.length < 1)
{
this.createInfoDialog();
}
-
+
this.lockScreen(true);
-
+
this.mask.css({
opacity : settings.dialogMaskOpacity,
backgroundColor : settings.dialogMaskBgColor
@@ -1430,15 +1443,15 @@
return this;
},
-
+
/**
* 隐藏关于Editor.md
* Hide about Editor.md dialog
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
- hideInfoDialog : function() {
+
+ hideInfoDialog : function() {
$("html,body").css("overflow-x", "");
this.infoDialog.hide();
this.mask.hide();
@@ -1446,68 +1459,68 @@
return this;
},
-
+
/**
* 锁屏
* lock screen
- *
+ *
* @param {Boolean} lock Boolean 布尔值,是否锁屏
* @returns {editormd} 返回editormd的实例对象
*/
-
+
lockScreen : function(lock) {
editormd.lockScreen(lock);
this.resize();
return this;
},
-
+
/**
* 编辑器界面重建,用于动态语言包或模块加载等
* Recreate editor
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
recreate : function() {
var _this = this;
var editor = this.editor;
var settings = this.settings;
-
+
this.codeMirror.remove();
-
+
this.setCodeMirror();
- if (!settings.readOnly)
+ if (!settings.readOnly)
{
if (editor.find(".editormd-dialog").length > 0) {
editor.find(".editormd-dialog").remove();
}
-
- if (settings.toolbar)
- {
- this.getToolbarHandles();
+
+ if (settings.toolbar)
+ {
+ this.getToolbarHandles();
this.setToolbar();
}
}
-
+
this.loadedDisplay(true);
return this;
},
-
+
/**
* 高亮预览HTML的pre代码部分
* highlight of preview codes
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
- previewCodeHighlight : function() {
+
+ previewCodeHighlight : function() {
var settings = this.settings;
var previewContainer = this.previewContainer;
-
- if (settings.previewCodeHighlight)
+
+ if (settings.previewCodeHighlight)
{
// previewContainer.find("pre").addClass("prettyprint");
//
@@ -1522,43 +1535,43 @@
return this;
},
-
+
/**
* 解析TeX(KaTeX)科学公式
* TeX(KaTeX) Renderer
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
katexRender : function() {
-
+
if (timer === null)
{
return this;
}
-
+
this.previewContainer.find("." + editormd.classNames.tex).each(function(){
var tex = $(this);
editormd.$katex.render(tex.text(), tex[0]);
-
+
tex.find(".katex").css("font-size", "1.6em");
- });
+ });
return this;
},
-
+
/**
* 解析和渲染流程图及时序图
* FlowChart and SequenceDiagram Renderer
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
flowChartAndSequenceDiagramRender : function() {
var $this = this;
var settings = this.settings;
var previewContainer = this.previewContainer;
-
+
if (editormd.isIE8) {
return this;
}
@@ -1591,13 +1604,13 @@
console.log(e);
}
}
-
+
var preview = $this.preview;
var codeMirror = $this.codeMirror;
var codeView = codeMirror.find(".CodeMirror-scroll");
var height = codeView.height();
- var scrollTop = codeView.scrollTop();
+ var scrollTop = codeView.scrollTop();
var percent = (scrollTop / codeView[0].scrollHeight);
var tocHeight = 0;
@@ -1605,43 +1618,43 @@
tocHeight += $(this).height();
});
- var tocMenuHeight = preview.find(".editormd-toc-menu").height();
+ var tocMenuHeight = preview.find(".editormd-toc-menu").height();
tocMenuHeight = (!tocMenuHeight) ? 0 : tocMenuHeight;
- if (scrollTop === 0)
+ if (scrollTop === 0)
{
preview.scrollTop(0);
- }
+ }
else if (scrollTop + height >= codeView[0].scrollHeight - 16)
- {
- preview.scrollTop(preview[0].scrollHeight);
- }
+ {
+ preview.scrollTop(preview[0].scrollHeight);
+ }
else
- {
+ {
preview.scrollTop((preview[0].scrollHeight + tocHeight + tocMenuHeight) * percent);
}
return this;
},
-
+
/**
* 注册键盘快捷键处理
* Register CodeMirror keyMaps (keyboard shortcuts).
- *
+ *
* @param {Object} keyMap KeyMap key/value {"(Ctrl/Shift/Alt)-Key" : function(){}}
* @returns {editormd} return this
*/
-
+
registerKeyMaps : function(keyMap) {
-
+
var _this = this;
var cm = this.cm;
var settings = this.settings;
var toolbarHandlers = editormd.toolbarHandlers;
var disabledKeyMaps = settings.disabledKeyMaps;
-
+
keyMap = keyMap || null;
-
+
if (keyMap)
{
for (var i in keyMap)
@@ -1661,7 +1674,7 @@
{
var _keyMap = editormd.keyMaps[k];
var handle = (typeof _keyMap === "string") ? $.proxy(toolbarHandlers[_keyMap], _this) : $.proxy(_keyMap, _this);
-
+
if ($.inArray(k, ["F9", "F10", "F11"]) < 0 && $.inArray(k, disabledKeyMaps) < 0)
{
var _map = {};
@@ -1670,15 +1683,15 @@
cm.addKeyMap(_map);
}
}
-
+
$(window).keydown(function(event) {
-
+
var keymaps = {
"120" : "F9",
"121" : "F10",
"122" : "F11"
};
-
+
if ( $.inArray(keymaps[event.keyCode], disabledKeyMaps) < 0 )
{
switch (event.keyCode)
@@ -1687,17 +1700,17 @@
$.proxy(toolbarHandlers["watch"], _this)();
return false;
break;
-
+
case 121:
$.proxy(toolbarHandlers["preview"], _this)();
return false;
break;
-
+
case 122:
- $.proxy(toolbarHandlers["fullscreen"], _this)();
+ $.proxy(toolbarHandlers["fullscreen"], _this)();
return false;
break;
-
+
default:
break;
}
@@ -1707,53 +1720,53 @@
return this;
},
-
+
/**
* 绑定同步滚动
- *
+ *
* @returns {editormd} return this
*/
-
+
bindScrollEvent : function() {
-
+
var _this = this;
var preview = this.preview;
var settings = this.settings;
var codeMirror = this.codeMirror;
var mouseOrTouch = editormd.mouseOrTouch;
-
+
if (!settings.syncScrolling) {
return this;
}
-
- var cmBindScroll = function() {
+
+ var cmBindScroll = function() {
codeMirror.find(".CodeMirror-scroll").bind(mouseOrTouch("scroll", "touchmove"), function(event) {
var height = $(this).height();
- var scrollTop = $(this).scrollTop();
+ var scrollTop = $(this).scrollTop();
var percent = (scrollTop / $(this)[0].scrollHeight);
-
+
var tocHeight = 0;
-
+
preview.find(".markdown-toc-list").each(function(){
tocHeight += $(this).height();
});
-
+
var tocMenuHeight = preview.find(".editormd-toc-menu").height();
tocMenuHeight = (!tocMenuHeight) ? 0 : tocMenuHeight;
- if (scrollTop === 0)
+ if (scrollTop === 0)
{
preview.scrollTop(0);
- }
+ }
else if (scrollTop + height >= $(this)[0].scrollHeight - 16)
- {
- preview.scrollTop(preview[0].scrollHeight);
- }
+ {
+ preview.scrollTop(preview[0].scrollHeight);
+ }
else
{
preview.scrollTop((preview[0].scrollHeight + tocHeight + tocMenuHeight) * percent);
}
-
+
$.proxy(settings.onscroll, _this)(event);
});
};
@@ -1763,26 +1776,26 @@
};
var previewBindScroll = function() {
-
+
preview.bind(mouseOrTouch("scroll", "touchmove"), function(event) {
var height = $(this).height();
- var scrollTop = $(this).scrollTop();
+ var scrollTop = $(this).scrollTop();
var percent = (scrollTop / $(this)[0].scrollHeight);
var codeView = codeMirror.find(".CodeMirror-scroll");
- if(scrollTop === 0)
+ if(scrollTop === 0)
{
codeView.scrollTop(0);
}
else if (scrollTop + height >= $(this)[0].scrollHeight)
{
- codeView.scrollTop(codeView[0].scrollHeight);
+ codeView.scrollTop(codeView[0].scrollHeight);
}
- else
+ else
{
codeView.scrollTop(codeView[0].scrollHeight * percent);
}
-
+
$.proxy(settings.onpreviewscroll, _this)(event);
});
@@ -1790,7 +1803,7 @@
var previewUnbindScroll = function() {
preview.unbind(mouseOrTouch("scroll", "touchmove"));
- };
+ };
codeMirror.bind({
mouseover : cmBindScroll,
@@ -1798,11 +1811,11 @@
touchstart : cmBindScroll,
touchend : cmUnbindScroll
});
-
+
if (settings.syncScrolling === "single") {
return this;
}
-
+
preview.bind({
mouseover : previewBindScroll,
mouseout : previewUnbindScroll,
@@ -1812,24 +1825,24 @@
return this;
},
-
+
bindChangeEvent : function() {
-
+
var _this = this;
var cm = this.cm;
var settings = this.settings;
-
+
if (!settings.syncScrolling) {
return this;
}
-
+
cm.on("change", function(_cm, changeObj) {
-
+
if (settings.watch)
{
_this.previewContainer.css("padding", settings.autoHeight ? "20px 20px 50px 40px" : "20px");
}
-
+
timer = setTimeout(function() {
clearTimeout(timer);
_this.save();
@@ -1839,210 +1852,210 @@
return this;
},
-
+
/**
* 加载队列完成之后的显示处理
* Display handle of the module queues loaded after.
- *
+ *
* @param {Boolean} recreate 是否为重建编辑器
* @returns {editormd} 返回editormd的实例对象
*/
-
+
loadedDisplay : function(recreate) {
-
+
recreate = recreate || false;
-
+
var _this = this;
var editor = this.editor;
var preview = this.preview;
var settings = this.settings;
-
+
this.containerMask.hide();
-
+
this.save();
-
+
if (settings.watch) {
preview.show();
}
-
+
editor.data("oldWidth", editor.width()).data("oldHeight", editor.height()); // 为了兼容Zepto
-
+
this.resize();
this.registerKeyMaps();
-
+
$(window).resize(function(){
_this.resize();
});
-
+
this.bindScrollEvent().bindChangeEvent();
-
+
if (!recreate)
{
$.proxy(settings.onload, this)();
}
-
+
this.state.loaded = true;
return this;
},
-
+
/**
* 设置编辑器的宽度
* Set editor width
- *
+ *
* @param {Number|String} width 编辑器宽度值
* @returns {editormd} 返回editormd的实例对象
*/
-
+
width : function(width) {
-
- this.editor.css("width", (typeof width === "number") ? width + "px" : width);
+
+ this.editor.css("width", (typeof width === "number") ? width + "px" : width);
this.resize();
-
+
return this;
},
-
+
/**
* 设置编辑器的高度
* Set editor height
- *
+ *
* @param {Number|String} height 编辑器高度值
* @returns {editormd} 返回editormd的实例对象
*/
-
+
height : function(height) {
-
- this.editor.css("height", (typeof height === "number") ? height + "px" : height);
+
+ this.editor.css("height", (typeof height === "number") ? height + "px" : height);
this.resize();
-
+
return this;
},
-
+
/**
* 调整编辑器的尺寸和布局
* Resize editor layout
- *
+ *
* @param {Number|String} [width=null] 编辑器宽度值
* @param {Number|String} [height=null] 编辑器高度值
* @returns {editormd} 返回editormd的实例对象
*/
-
+
resize : function(width, height) {
-
+
width = width || null;
height = height || null;
-
+
var state = this.state;
var editor = this.editor;
var preview = this.preview;
var toolbar = this.toolbar;
var settings = this.settings;
var codeMirror = this.codeMirror;
-
+
if (width)
{
editor.css("width", (typeof width === "number") ? width + "px" : width);
}
-
+
if (settings.autoHeight && !state.fullscreen && !state.preview)
{
editor.css("height", "auto");
codeMirror.css("height", "auto");
- }
- else
+ }
+ else
{
- if (height)
+ if (height)
{
editor.css("height", (typeof height === "number") ? height + "px" : height);
}
-
+
if (state.fullscreen)
{
editor.height($(window).height());
}
- if (settings.toolbar && !settings.readOnly)
+ if (settings.toolbar && !settings.readOnly)
{
codeMirror.css("margin-top", toolbar.height() + 1).height(editor.height() - toolbar.height());
- }
+ }
else
{
codeMirror.css("margin-top", 0).height(editor.height());
}
}
-
- if(settings.watch)
+
+ if(settings.watch)
{
codeMirror.width(editor.width() / 2);
preview.width((!state.preview) ? editor.width() / 2 : editor.width());
-
+
this.previewContainer.css("padding", settings.autoHeight ? "20px 20px 50px 40px" : "20px");
-
- if (settings.toolbar && !settings.readOnly)
+
+ if (settings.toolbar && !settings.readOnly)
{
preview.css("top", toolbar.height() + 1);
- }
- else
+ }
+ else
{
preview.css("top", 0);
}
-
+
if (settings.autoHeight && !state.fullscreen && !state.preview)
{
preview.height("");
}
else
- {
+ {
var previewHeight = (settings.toolbar && !settings.readOnly) ? editor.height() - toolbar.height() : editor.height();
-
+
preview.height(previewHeight);
}
- }
- else
+ }
+ else
{
codeMirror.width(editor.width());
preview.hide();
}
-
- if (state.loaded)
+
+ if (state.loaded)
{
$.proxy(settings.onresize, this)();
}
return this;
},
-
+
/**
* 解析和保存Markdown代码
* Parse & Saving Markdown source code
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
save : function() {
-
+
if (timer === null)
{
return this;
}
-
+
var _this = this;
var state = this.state;
var settings = this.settings;
- var cm = this.cm;
+ var cm = this.cm;
var cmValue = cm.getValue();
var previewContainer = this.previewContainer;
- if (settings.mode !== "gfm" && settings.mode !== "markdown")
+ if (settings.mode !== "gfm" && settings.mode !== "markdown")
{
this.markdownTextarea.val(cmValue);
-
+
return this;
}
-
+
var marked = editormd.$marked;
- var markdownToC = this.markdownToC = [];
- var rendererOptions = this.markedRendererOptions = {
+ var markdownToC = this.markdownToC = [];
+ var rendererOptions = this.markedRendererOptions = {
toc : settings.toc,
tocm : settings.tocm,
tocStartLevel : settings.tocStartLevel,
@@ -2057,7 +2070,7 @@
previewCodeHighlight : settings.previewCodeHighlight,
mermaid : settings.mermaid,
};
-
+
var markedOptions = this.markedOptions = {
renderer : editormd.markedRenderer(markdownToC, rendererOptions),
gfm : true,
@@ -2068,75 +2081,75 @@
smartLists : true,
smartypants : true
};
-
+
marked.setOptions(markedOptions);
-
+
var newMarkdownDoc = editormd.$marked(cmValue, markedOptions);
if(settings.debug) {
console.info("cmValue", cmValue, newMarkdownDoc);
}
newMarkdownDoc = editormd.filterHTMLTags(newMarkdownDoc, settings.htmlDecode);
-
+
//console.error("cmValue", cmValue, newMarkdownDoc);
-
+
this.markdownTextarea.text(cmValue);
-
+
cm.save();
-
- if (settings.saveHTMLToTextarea)
+
+ if (settings.saveHTMLToTextarea)
{
this.htmlTextarea.text(newMarkdownDoc);
}
-
+
if(settings.watch || (!settings.watch && state.preview))
{
previewContainer.html(newMarkdownDoc);
this.previewCodeHighlight();
-
- if (settings.toc)
+
+ if (settings.toc)
{
var tocContainer = (settings.tocContainer === "") ? previewContainer : $(settings.tocContainer);
var tocMenu = tocContainer.find("." + this.classPrefix + "toc-menu");
-
+
tocContainer.attr("previewContainer", (settings.tocContainer === "") ? "true" : "false");
-
+
if (settings.tocContainer !== "" && tocMenu.length > 0)
{
tocMenu.remove();
}
-
+
editormd.markdownToCRenderer(markdownToC, tocContainer, settings.tocDropdown, settings.tocStartLevel);
-
+
if (settings.tocDropdown || tocContainer.find("." + this.classPrefix + "toc-menu").length > 0)
{
editormd.tocDropdownMenu(tocContainer, (settings.tocTitle !== "") ? settings.tocTitle : this.lang.tocTitle);
}
-
+
if (settings.tocContainer !== "")
{
previewContainer.find(".markdown-toc").css("border", "none");
}
}
-
+
if (settings.tex)
{
- if (!editormd.kaTeXLoaded && settings.autoLoadModules)
+ if (!editormd.kaTeXLoaded && settings.autoLoadModules)
{
editormd.loadKaTeX(function() {
editormd.$katex = katex;
editormd.kaTeXLoaded = true;
_this.katexRender();
});
- }
- else
+ }
+ else
{
editormd.$katex = katex;
this.katexRender();
}
- }
-
+ }
+
if (settings.flowChart || settings.sequenceDiagram || settings.mermaid)
{
flowchartTimer = setTimeout(function(){
@@ -2146,7 +2159,7 @@
}, 10);
}
- if (state.loaded)
+ if (state.loaded)
{
$.proxy(settings.onchange, this)();
}
@@ -2154,215 +2167,215 @@
return this;
},
-
+
/**
* 聚焦光标位置
* Focusing the cursor position
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
focus : function() {
this.cm.focus();
return this;
},
-
+
/**
* 设置光标的位置
* Set cursor position
- *
+ *
* @param {Object} cursor 要设置的光标位置键值对象,例:{line:1, ch:0}
* @returns {editormd} 返回editormd的实例对象
*/
-
+
setCursor : function(cursor) {
this.cm.setCursor(cursor);
return this;
},
-
+
/**
* 获取当前光标的位置
* Get the current position of the cursor
- *
+ *
* @returns {Cursor} 返回一个光标Cursor对象
*/
-
+
getCursor : function() {
return this.cm.getCursor();
},
-
+
/**
* 设置光标选中的范围
* Set cursor selected ranges
- *
+ *
* @param {Object} from 开始位置的光标键值对象,例:{line:1, ch:0}
* @param {Object} to 结束位置的光标键值对象,例:{line:1, ch:0}
* @returns {editormd} 返回editormd的实例对象
*/
-
+
setSelection : function(from, to) {
-
+
this.cm.setSelection(from, to);
-
+
return this;
},
-
+
/**
* 获取光标选中的文本
* Get the texts from cursor selected
- *
+ *
* @returns {String} 返回选中文本的字符串形式
*/
-
+
getSelection : function() {
return this.cm.getSelection();
},
-
+
/**
* 设置光标选中的文本范围
* Set the cursor selection ranges
- *
+ *
* @param {Array} ranges cursor selection ranges array
* @returns {Array} return this
*/
-
+
setSelections : function(ranges) {
this.cm.setSelections(ranges);
-
+
return this;
},
-
+
/**
* 获取光标选中的文本范围
* Get the cursor selection ranges
- *
+ *
* @returns {Array} return selection ranges array
*/
-
+
getSelections : function() {
return this.cm.getSelections();
},
-
+
/**
* 替换当前光标选中的文本或在当前光标处插入新字符
* Replace the text at the current cursor selected or insert a new character at the current cursor position
- *
+ *
* @param {String} value 要插入的字符值
* @returns {editormd} 返回editormd的实例对象
*/
-
+
replaceSelection : function(value) {
this.cm.replaceSelection(value);
return this;
},
-
+
/**
* 在当前光标处插入新字符
* Insert a new character at the current cursor position
*
* 同replaceSelection()方法
* With the replaceSelection() method
- *
+ *
* @param {String} value 要插入的字符值
* @returns {editormd} 返回editormd的实例对象
*/
-
+
insertValue : function(value) {
this.replaceSelection(value);
return this;
},
-
+
/**
* 追加markdown
* append Markdown to editor
- *
+ *
* @param {String} md 要追加的markdown源文档
* @returns {editormd} 返回editormd的实例对象
*/
-
+
appendMarkdown : function(md) {
var settings = this.settings;
var cm = this.cm;
-
+
cm.setValue(cm.getValue() + md);
-
+
return this;
},
-
+
/**
* 设置和传入编辑器的markdown源文档
* Set Markdown source document
- *
+ *
* @param {String} md 要传入的markdown源文档
* @returns {editormd} 返回editormd的实例对象
*/
-
+
setMarkdown : function(md) {
this.cm.setValue(md || this.settings.markdown);
-
+
return this;
},
-
+
/**
* 获取编辑器的markdown源文档
* Set Editor.md markdown/CodeMirror value
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
getMarkdown : function() {
return this.cm.getValue();
},
-
+
/**
* 获取编辑器的源文档
* Get CodeMirror value
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
getValue : function() {
return this.cm.getValue();
},
-
+
/**
* 设置编辑器的源文档
* Set CodeMirror value
- *
+ *
* @param {String} value set code/value/string/text
* @returns {editormd} 返回editormd的实例对象
*/
-
+
setValue : function(value) {
this.cm.setValue(value);
-
+
return this;
},
-
+
/**
* 清空编辑器
* Empty CodeMirror editor container
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
clear : function() {
this.cm.setValue("");
-
+
return this;
},
-
+
/**
* 获取解析后存放在Textarea的HTML源码
* Get parsed html code from Textarea
- *
+ *
* @returns {String} 返回HTML源码
*/
-
+
getHTML : function() {
if (!this.settings.saveHTMLToTextarea)
{
@@ -2370,28 +2383,28 @@
return false;
}
-
+
return this.htmlTextarea.val();
},
-
+
/**
* getHTML()的别名
* getHTML (alias)
- *
+ *
* @returns {String} Return html code 返回HTML源码
*/
-
+
getTextareaSavedHTML : function() {
return this.getHTML();
},
-
+
/**
* 获取预览窗口的HTML源码
* Get html from preview container
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
getPreviewedHTML : function() {
if (!this.settings.watch)
{
@@ -2399,137 +2412,137 @@
return false;
}
-
+
return this.previewContainer.html();
},
-
+
/**
* 开启实时预览
* Enable real-time watching
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
- watch : function(callback) {
+
+ watch : function(callback) {
var settings = this.settings;
-
+
if ($.inArray(settings.mode, ["gfm", "markdown"]) < 0)
{
return this;
}
-
+
this.state.watching = settings.watch = true;
this.preview.show();
-
+
if (this.toolbar)
{
var watchIcon = settings.toolbarIconsClass.watch;
var unWatchIcon = settings.toolbarIconsClass.unwatch;
-
+
var icon = this.toolbar.find(".fa[name=watch]");
icon.parent().attr("title", settings.lang.toolbar.watch);
icon.removeClass(unWatchIcon).addClass(watchIcon);
}
-
- this.codeMirror.css("border-right", "1px solid #ddd").width(this.editor.width() / 2);
-
+
+ this.codeMirror.css("border-right", "1px solid #ddd").width(this.editor.width() / 2);
+
timer = 0;
-
+
this.save().resize();
-
+
if (!settings.onwatch)
{
settings.onwatch = callback || function() {};
}
-
+
$.proxy(settings.onwatch, this)();
-
+
return this;
},
-
+
/**
* 关闭实时预览
* Disable real-time watching
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
unwatch : function(callback) {
var settings = this.settings;
this.state.watching = settings.watch = false;
this.preview.hide();
-
- if (this.toolbar)
+
+ if (this.toolbar)
{
var watchIcon = settings.toolbarIconsClass.watch;
var unWatchIcon = settings.toolbarIconsClass.unwatch;
-
+
var icon = this.toolbar.find(".fa[name=watch]");
icon.parent().attr("title", settings.lang.toolbar.unwatch);
icon.removeClass(watchIcon).addClass(unWatchIcon);
}
-
+
this.codeMirror.css("border-right", "none").width(this.editor.width());
-
+
this.resize();
-
+
if (!settings.onunwatch)
{
settings.onunwatch = callback || function() {};
}
-
+
$.proxy(settings.onunwatch, this)();
-
+
return this;
},
-
+
/**
* 显示编辑器
* Show editor
- *
+ *
* @param {Function} [callback=function()] 回调函数
* @returns {editormd} 返回editormd的实例对象
*/
-
+
show : function(callback) {
callback = callback || function() {};
-
+
var _this = this;
this.editor.show(0, function() {
$.proxy(callback, _this)();
});
-
+
return this;
},
-
+
/**
* 隐藏编辑器
* Hide editor
- *
+ *
* @param {Function} [callback=function()] 回调函数
* @returns {editormd} 返回editormd的实例对象
*/
-
+
hide : function(callback) {
callback = callback || function() {};
-
+
var _this = this;
this.editor.hide(0, function() {
$.proxy(callback, _this)();
});
-
+
return this;
},
-
+
/**
* 隐藏编辑器部分,只预览HTML
* Enter preview html state
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
previewing : function() {
-
+
var _this = this;
var editor = this.editor;
var preview = this.preview;
@@ -2537,18 +2550,18 @@
var settings = this.settings;
var codeMirror = this.codeMirror;
var previewContainer = this.previewContainer;
-
+
if ($.inArray(settings.mode, ["gfm", "markdown"]) < 0) {
return this;
}
-
+
if (settings.toolbar && toolbar) {
toolbar.toggle();
toolbar.find(".fa[name=preview]").toggleClass("active");
}
-
+
codeMirror.toggle();
-
+
var escHandle = function(event) {
if (event.shiftKey && event.keyCode === 27) {
_this.previewed();
@@ -2562,20 +2575,20 @@
if (this.state.fullscreen) {
preview.css("background", "#fff");
}
-
+
editor.find("." + this.classPrefix + "preview-close-btn").show().bind(editormd.mouseOrTouch("click", "touchend"), function(){
_this.previewed();
});
-
+
if (!settings.watch)
{
this.save();
- }
- else
+ }
+ else
{
previewContainer.css("padding", "");
}
-
+
previewContainer.addClass(this.classPrefix + "preview-active");
preview.show().css({
@@ -2584,30 +2597,30 @@
width : editor.width(),
height : (settings.autoHeight && !this.state.fullscreen) ? "auto" : editor.height()
});
-
+
if (this.state.loaded)
{
$.proxy(settings.onpreviewing, this)();
}
$(window).bind("keyup", escHandle);
- }
- else
+ }
+ else
{
$(window).unbind("keyup", escHandle);
this.previewed();
}
},
-
+
/**
* 显示编辑器部分,退出只预览HTML
* Exit preview html state
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
previewed : function() {
-
+
var editor = this.editor;
var preview = this.preview;
var toolbar = this.toolbar;
@@ -2616,25 +2629,25 @@
var previewCloseBtn = editor.find("." + this.classPrefix + "preview-close-btn");
this.state.preview = false;
-
+
this.codeMirror.show();
-
+
if (settings.toolbar) {
toolbar.show();
}
-
+
preview[(settings.watch) ? "show" : "hide"]();
-
+
previewCloseBtn.hide().unbind(editormd.mouseOrTouch("click", "touchend"));
-
+
previewContainer.removeClass(this.classPrefix + "preview-active");
-
+
if (settings.watch)
{
previewContainer.css("padding", "20px");
}
-
- preview.css({
+
+ preview.css({
background : null,
position : "absolute",
width : editor.width() / 2,
@@ -2646,19 +2659,19 @@
{
$.proxy(settings.onpreviewed, this)();
}
-
+
return this;
},
-
+
/**
* 编辑器全屏显示
* Fullscreen show
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
fullscreen : function() {
-
+
var _this = this;
var state = this.state;
var editor = this.editor;
@@ -2666,13 +2679,13 @@
var toolbar = this.toolbar;
var settings = this.settings;
var fullscreenClass = this.classPrefix + "fullscreen";
-
+
if (toolbar) {
- toolbar.find(".fa[name=fullscreen]").parent().toggleClass("active");
+ toolbar.find(".fa[name=fullscreen]").parent().toggleClass("active");
}
-
+
var escHandle = function(event) {
- if (!event.shiftKey && event.keyCode === 27)
+ if (!event.shiftKey && event.keyCode === 27)
{
if (state.fullscreen)
{
@@ -2681,50 +2694,50 @@
}
};
- if (!editor.hasClass(fullscreenClass))
+ if (!editor.hasClass(fullscreenClass))
{
state.fullscreen = true;
$("html,body").css("overflow", "hidden");
-
+
editor.css({
width : $(window).width(),
height : $(window).height()
}).addClass(fullscreenClass);
this.resize();
-
+
$.proxy(settings.onfullscreen, this)();
$(window).bind("keyup", escHandle);
}
else
- {
- $(window).unbind("keyup", escHandle);
+ {
+ $(window).unbind("keyup", escHandle);
this.fullscreenExit();
}
return this;
},
-
+
/**
* 编辑器退出全屏显示
* Exit fullscreen state
- *
+ *
* @returns {editormd} 返回editormd的实例对象
*/
-
+
fullscreenExit : function() {
-
+
var editor = this.editor;
var settings = this.settings;
var toolbar = this.toolbar;
- var fullscreenClass = this.classPrefix + "fullscreen";
-
+ var fullscreenClass = this.classPrefix + "fullscreen";
+
this.state.fullscreen = false;
-
+
if (toolbar) {
- toolbar.find(".fa[name=fullscreen]").parent().removeClass("active");
+ toolbar.find(".fa[name=fullscreen]").parent().removeClass("active");
}
$("html,body").css("overflow", "");
@@ -2735,43 +2748,43 @@
}).removeClass(fullscreenClass);
this.resize();
-
+
$.proxy(settings.onfullscreenExit, this)();
return this;
},
-
+
/**
* 加载并执行插件
* Load and execute the plugin
- *
+ *
* @param {String} name plugin name / function name
* @param {String} path plugin load path
* @returns {editormd} 返回editormd的实例对象
*/
-
+
executePlugin : function(name, path) {
-
+
var _this = this;
var cm = this.cm;
var settings = this.settings;
-
+
path = settings.pluginPath + path;
-
- if (typeof define === "function")
- {
+
+ if (typeof define === "function")
+ {
if (typeof this[name] === "undefined")
{
alert("Error: " + name + " plugin is not found, you are not load this plugin.");
-
+
return this;
}
-
+
this[name](cm);
-
+
return this;
}
-
+
if ($.inArray(path, editormd.loadFiles.plugin) < 0)
{
editormd.loadPlugin(path, function() {
@@ -2783,79 +2796,79 @@
{
$.proxy(editormd.loadPlugins[name], this)(cm);
}
-
+
return this;
},
-
+
/**
* 搜索替换
* Search & replace
- *
+ *
* @param {String} command CodeMirror serach commands, "find, fintNext, fintPrev, clearSearch, replace, replaceAll"
* @returns {editormd} return this
*/
-
+
search : function(command) {
var settings = this.settings;
-
+
if (!settings.searchReplace)
{
alert("Error: settings.searchReplace == false");
return this;
}
-
+
if (!settings.readOnly)
{
this.cm.execCommand(command || "find");
}
-
+
return this;
},
-
- searchReplace : function() {
+
+ searchReplace : function() {
this.search("replace");
-
+
return this;
},
-
- searchReplaceAll : function() {
+
+ searchReplaceAll : function() {
this.search("replaceAll");
-
+
return this;
}
};
-
- editormd.fn.init.prototype = editormd.fn;
-
+
+ editormd.fn.init.prototype = editormd.fn;
+
/**
* 锁屏
* lock screen when dialog opening
- *
+ *
* @returns {void}
*/
editormd.dialogLockScreen = function() {
var settings = this.settings || {dialogLockScreen : true};
-
- if (settings.dialogLockScreen)
- {
+
+ if (settings.dialogLockScreen)
+ {
$("html,body").css("overflow", "hidden");
this.resize();
}
};
-
+
/**
* 显示透明背景层
* Display mask layer when dialog opening
- *
+ *
* @param {Object} dialog dialog jQuery object
* @returns {void}
*/
-
+
editormd.dialogShowMask = function(dialog) {
var editor = this.editor;
var settings = this.settings || {dialogShowMask : true};
-
+
dialog.css({
top : ($(window).height() - dialog.height()) / 2 + "px",
left : ($(window).width() - dialog.width()) / 2 + "px"
@@ -2870,11 +2883,11 @@
undo : function() {
this.cm.undo();
},
-
+
redo : function() {
this.cm.redo();
},
-
+
bold : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@@ -2886,7 +2899,7 @@
cm.setCursor(cursor.line, cursor.ch + 2);
}
},
-
+
del : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@@ -2930,7 +2943,7 @@
//cm.replaceSelection("> " + selection);
//cm.setCursor(cursor.line, (selection === "") ? cursor.ch + 2 : cursor.ch + selection.length + 2);
},
-
+
ucfirst : function() {
var cm = this.cm;
var selection = cm.getSelection();
@@ -2939,7 +2952,7 @@
cm.replaceSelection(editormd.firstUpperCase(selection));
cm.setSelections(selections);
},
-
+
ucwords : function() {
var cm = this.cm;
var selection = cm.getSelection();
@@ -2948,7 +2961,7 @@
cm.replaceSelection(editormd.wordsFirstUpperCase(selection));
cm.setSelections(selections);
},
-
+
uppercase : function() {
var cm = this.cm;
var selection = cm.getSelection();
@@ -2957,13 +2970,13 @@
cm.replaceSelection(selection.toUpperCase());
cm.setSelections(selections);
},
-
+
lowercase : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
var selections = cm.listSelections();
-
+
cm.replaceSelection(selection.toLowerCase());
cm.setSelections(selections);
},
@@ -3075,15 +3088,15 @@
var cursor = cm.getCursor();
var selection = cm.getSelection();
- if (selection === "")
+ if (selection === "")
{
cm.replaceSelection("- " + selection);
- }
- else
+ }
+ else
{
var selectionText = selection.split("\n");
- for (var i = 0, len = selectionText.length; i < len; i++)
+ for (var i = 0, len = selectionText.length; i < len; i++)
{
selectionText[i] = (selectionText[i] === "") ? "" : "- " + selectionText[i];
}
@@ -3097,7 +3110,7 @@
var cursor = cm.getCursor();
var selection = cm.getSelection();
- if(selection === "")
+ if(selection === "")
{
cm.replaceSelection("1. " + selection);
}
@@ -3105,7 +3118,7 @@
{
var selectionText = selection.split("\n");
- for (var i = 0, len = selectionText.length; i < len; i++)
+ for (var i = 0, len = selectionText.length; i < len; i++)
{
selectionText[i] = (selectionText[i] === "") ? "" : (i+1) + ". " + selectionText[i];
}
@@ -3128,7 +3141,7 @@
alert("settings.tex === false");
return this;
}
-
+
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
@@ -3154,7 +3167,7 @@
alert("settings.pageBreak === false");
return this;
}
-
+
var cm = this.cm;
var selection = cm.getSelection();
@@ -3164,7 +3177,7 @@
image : function() {
this.executePlugin("imageDialog", "image-dialog/image-dialog");
},
-
+
code : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@@ -3178,17 +3191,17 @@
},
"code-block" : function() {
- this.executePlugin("codeBlockDialog", "code-block-dialog/code-block-dialog");
+ this.executePlugin("codeBlockDialog", "code-block-dialog/code-block-dialog");
},
"preformatted-text" : function() {
this.executePlugin("preformattedTextDialog", "preformatted-text-dialog/preformatted-text-dialog");
},
-
+
table : function() {
- this.executePlugin("tableDialog", "table-dialog/table-dialog");
+ this.executePlugin("tableDialog", "table-dialog/table-dialog");
},
-
+
datetime : function() {
var cm = this.cm;
var selection = cm.getSelection();
@@ -3198,20 +3211,20 @@
cm.replaceSelection(datefmt);
},
-
+
emoji : function() {
this.executePlugin("emojiDialog", "emoji-dialog/emoji-dialog");
},
-
+
"html-entities" : function() {
this.executePlugin("htmlEntitiesDialog", "html-entities-dialog/html-entities-dialog");
},
-
+
"goto-line" : function() {
this.executePlugin("gotoLineDialog", "goto-line-dialog/goto-line-dialog");
},
- watch : function() {
+ watch : function() {
this[this.settings.watch ? "unwatch" : "watch"]();
},
@@ -3226,7 +3239,7 @@
clear : function() {
this.clear();
},
-
+
search : function() {
this.search();
},
@@ -3239,7 +3252,7 @@
this.showInfoDialog();
}
};
-
+
editormd.keyMaps = {
"Ctrl-1" : "h1",
"Ctrl-2" : "h2",
@@ -3249,12 +3262,12 @@
"Ctrl-6" : "h6",
"Ctrl-B" : "bold", // if this is string == editormd.toolbarHandlers.xxxx
"Ctrl-D" : "datetime",
-
+
"Ctrl-E" : function() { // emoji
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
-
+
if (!this.settings.emoji)
{
alert("Error: settings.emoji == false");
@@ -3271,12 +3284,12 @@
"Ctrl-H" : "hr",
"Ctrl-I" : "italic",
"Ctrl-K" : "code",
-
+
"Ctrl-L" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
-
+
var title = (selection === "") ? "" : " \""+selection+"\"";
cm.replaceSelection("[" + selection + "]("+title+")");
@@ -3286,12 +3299,12 @@
}
},
"Ctrl-U" : "list-ul",
-
+
"Shift-Ctrl-A" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
-
+
if (!this.settings.atLink)
{
alert("Error: settings.atLink == false");
@@ -3304,24 +3317,24 @@
cm.setCursor(cursor.line, cursor.ch + 1);
}
},
-
+
"Shift-Ctrl-C" : "code",
"Shift-Ctrl-Q" : "quote",
"Shift-Ctrl-S" : "del",
"Shift-Ctrl-K" : "tex", // KaTeX
-
+
"Shift-Alt-C" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
-
+
cm.replaceSelection(["```", selection, "```"].join("\n"));
if (selection === "") {
cm.setCursor(cursor.line, cursor.ch + 3);
- }
+ }
},
-
+
"Shift-Ctrl-Alt-C" : "code-block",
"Shift-Ctrl-H" : "html-entities",
"Shift-Alt-H" : "help",
@@ -3330,12 +3343,12 @@
"Shift-Alt-U" : "ucwords",
"Shift-Ctrl-Alt-U" : "ucfirst",
"Shift-Alt-L" : "lowercase",
-
+
"Shift-Ctrl-I" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
-
+
var title = (selection === "") ? "" : " \""+selection+"\"";
cm.replaceSelection("![" + selection + "]("+title+")");
@@ -3344,7 +3357,7 @@
cm.setCursor(cursor.line, cursor.ch + 4);
}
},
-
+
"Shift-Ctrl-Alt-I" : "image",
"Shift-Ctrl-L" : "link",
"Shift-Ctrl-O" : "list-ol",
@@ -3355,59 +3368,59 @@
"F10" : "preview",
"F11" : "fullscreen",
};
-
+
/**
* 清除字符串两边的空格
* Clear the space of strings both sides.
- *
+ *
* @param {String} str string
- * @returns {String} trimed string
+ * @returns {String} trimed string
*/
-
+
var trim = function(str) {
return (!String.prototype.trim) ? str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "") : str.trim();
};
-
+
editormd.trim = trim;
-
+
/**
* 所有单词首字母大写
* Words first to uppercase
- *
+ *
* @param {String} str string
* @returns {String} string
*/
-
+
var ucwords = function (str) {
- return str.toLowerCase().replace(/\b(\w)|\s(\w)/g, function($1) {
+ return str.toLowerCase().replace(/\b(\w)|\s(\w)/g, function($1) {
return $1.toUpperCase();
});
};
-
+
editormd.ucwords = editormd.wordsFirstUpperCase = ucwords;
-
+
/**
* 字符串首字母大写
* Only string first char to uppercase
- *
+ *
* @param {String} str string
* @returns {String} string
*/
-
- var firstUpperCase = function(str) {
+
+ var firstUpperCase = function(str) {
return str.toLowerCase().replace(/\b(\w)/, function($1){
return $1.toUpperCase();
});
};
-
+
var ucfirst = firstUpperCase;
-
+
editormd.firstUpperCase = editormd.ucfirst = firstUpperCase;
-
+
editormd.urls = {
atLinkBase : "https://github.com/"
};
-
+
editormd.regexs = {
atLink : /@(\w+)/g,
email : /(\w+)@(\w+)\.(\w+)\.?(\w+)?/g,
@@ -3435,7 +3448,7 @@
/**
* 自定义marked的解析器
* Custom Marked renderer rules
- *
+ *
* @param {Array} markdownToC 传入用于接收TOC的数组
* @returns {Renderer} markedRenderer 返回marked的Renderer自定义对象
*/
@@ -3444,7 +3457,7 @@
var defaults = {
toc : true, // Table of contents
tocm : false,
- tocStartLevel : 1, // Said from H1 to create ToC
+ tocStartLevel : 1, // Said from H1 to create ToC
pageBreak : true,
atLink : true, // for @link
emailLink : true, // for mail address auto link
@@ -3455,12 +3468,12 @@
sequenceDiagram : false, // sequenceDiagram.js only support IE9+
mermaid : true,
};
-
- var settings = $.extend(defaults, options || {});
+
+ var settings = $.extend(defaults, options || {});
var marked = editormd.$marked;
var markedRenderer = new marked.Renderer();
- markdownToC = markdownToC || [];
-
+ markdownToC = markdownToC || [];
+
var regexs = editormd.regexs;
var atLinkReg = regexs.atLink;
var emojiReg = regexs.emoji;
@@ -3543,11 +3556,11 @@
};
markedRenderer.emoji = function(text) {
-
- text = text.replace(editormd.regexs.emojiDatetime, function($1) {
+
+ text = text.replace(editormd.regexs.emojiDatetime, function($1) {
return $1.replace(/:/g, ":");
});
-
+
var matchs = text.match(emojiReg);
if (!matchs || !settings.emoji) {
@@ -3555,7 +3568,7 @@
}
for (var i = 0, len = matchs.length; i < len; i++)
- {
+ {
if (matchs[i] === ":+1:") {
matchs[i] = ":\\+1:";
}
@@ -3565,11 +3578,11 @@
var name = $1.replace(/:/g, "");
if (faMatchs)
- {
+ {
for (var fa = 0, len1 = faMatchs.length; fa < len1; fa++)
{
var faName = faMatchs[fa].replace(/:/g, "");
-
+
return "
";
}
}
@@ -3578,15 +3591,15 @@
var emdlogoMathcs = $1.match(editormdLogoReg);
var twemojiMatchs = $1.match(twemojiReg);
- if (emdlogoMathcs)
- {
+ if (emdlogoMathcs)
+ {
for (var x = 0, len2 = emdlogoMathcs.length; x < len2; x++)
{
var logoName = emdlogoMathcs[x].replace(/:/g, "");
return "
";
}
}
- else if (twemojiMatchs)
+ else if (twemojiMatchs)
{
for (var t = 0, len3 = twemojiMatchs.length; t < len3; t++)
{
@@ -3612,8 +3625,8 @@
markedRenderer.atLink = function(text) {
if (atLinkReg.test(text))
- {
- if (settings.atLink)
+ {
+ if (settings.atLink)
{
text = text.replace(emailReg, function($1, $2, $3, $4) {
return $1.replace(/@/g, "_#_@_#_");
@@ -3623,7 +3636,7 @@
return "
" + $1 + "";
}).replace(/_#_@_#_/g, "@");
}
-
+
if (settings.emailLink)
{
text = text.replace(emailLinkReg, function($1, $2, $3, $4, $5) {
@@ -3636,7 +3649,7 @@
return text;
};
-
+
markedRenderer.link = function (href, title, text) {
if (this.options.sanitize) {
@@ -3658,14 +3671,14 @@
if(href.indexOf("http://") === 0 || href.indexOf("https://") === 0) {
out += "target=\"_blank\"";
}
-
+
if (atLinkReg.test(title) || atLinkReg.test(text))
{
if (title)
{
out += " title=\"" + title.replace(/@/g, "@");
}
-
+
return out + "\">" + text.replace(/@/g, "@") + "";
}
@@ -3677,14 +3690,14 @@
return out;
};
-
+
markedRenderer.heading = function(text, level, raw) {
-
+
var linkText = text;
var hasLinkReg = /\s*\
]*)\>(.*)\<\/a\>\s*/;
var getLinkTextReg = /\s*\]+)\>([^\>]*)\<\/a\>\s*/g;
- if (hasLinkReg.test(text))
+ if (hasLinkReg.test(text))
{
var tempText = [];
text = text.split(/\]+)\>([^\>]*)\<\/a\>/);
@@ -3696,23 +3709,23 @@
text = tempText.join(" ");
}
-
+
text = trim(text);
-
+
var escapedText = text.toLowerCase().replace(/[^\w]+/g, "-");
var toc = {
text : text,
level : level,
slug : escapedText
};
-
+
var isChinese = /^[\u4e00-\u9fa5]+$/.test(text);
var id = (isChinese) ? escape(text).replace(/\%/g, "") : text.toLowerCase().replace(/[^\w]+/g, "-");
markdownToC.push(toc);
-
+
var headingHTML = "";
-
+
headingHTML += "";
headingHTML += "";
headingHTML += (hasLinkReg) ? this.atLink(this.emoji(linkText)) : this.atLink(this.emoji(text));
@@ -3720,13 +3733,13 @@
return headingHTML;
};
-
+
markedRenderer.pageBreak = function(text) {
if (pageBreakReg.test(text) && settings.pageBreak)
{
text = "
";
}
-
+
return text;
};
@@ -3736,25 +3749,25 @@
var isTeXAddClass = (isTeXLine) ? " class=\"" + editormd.classNames.tex + "\"" : " class=\"line\"";
var isToC = (settings.tocm) ? /^(\[TOC\]|\[TOCM\])$/.test(text) : /^\[TOC\]$/.test(text);
var isToCMenu = /^\[TOCM\]$/.test(text);
-
- if (!isTeXLine && isTeXInline)
+
+ if (!isTeXLine && isTeXInline)
{
text = text.replace(/(\$\$([^\$]*)\$\$)+/g, function($1, $2) {
return "" + $2.replace(/\$/g, "") + "";
});
- }
- else
+ }
+ else
{
text = (isTeXLine) ? text.replace(/\$/g, "") : text;
}
-
+
var tocHTML = "" + text + "
";
-
+
return (isToC) ? ( (isToCMenu) ? "
" : tocHTML )
: ( (pageBreakReg.test(text)) ? this.pageBreak(text) : "" + this.atLink(this.emoji(text)) + "
\n" );
};
- markedRenderer.code = function (code, lang, escaped) {
+ markedRenderer.code = function (code, lang, escaped) {
if (lang === "seq" || lang === "sequence")
{
@@ -3774,12 +3787,12 @@
else if ( lang === "flow")
{
return "" + code + "
";
- }
+ }
else if ( lang === "math" || lang === "latex" || lang === "katex")
{
return "" + code + "
";
- }
- else
+ }
+ else
{
return marked.Renderer.prototype.code.apply(this, arguments);
@@ -3789,19 +3802,19 @@
markedRenderer.tablecell = function(content, flags) {
var type = (flags.header) ? "th" : "td";
var tag = (flags.align) ? "<" + type +" style=\"text-align:" + flags.align + "\">" : "<" + type + ">";
-
+
return tag + this.atLink(this.emoji(content)) + "" + type + ">\n";
};
markedRenderer.listitem = function(text) {
- if (settings.taskList && /^\s*\[[x\s]\]\s*/.test(text))
+ if (settings.taskList && /^\s*\[[x\s]\]\s*/.test(text))
{
text = text.replace(/^\s*\[\s\]\s*/, " ")
.replace(/^\s*\[x\]\s*/, " ");
return "" + this.atLink(this.emoji(text)) + "";
}
- else
+ else
{
return "" + this.atLink(this.emoji(text)) + "";
}
@@ -3809,47 +3822,47 @@
markedRenderer.checkbox = function(checked){
return checked ? ' ' : ' ';
};
-
+
return markedRenderer;
};
-
+
/**
*
* 生成TOC(Table of Contents)
* Creating ToC (Table of Contents)
- *
+ *
* @param {Array} toc 从marked获取的TOC数组列表
* @param {Element} container 插入TOC的容器元素
* @param {Integer} startLevel Hx 起始层级
* @returns {Object} tocContainer 返回ToC列表容器层的jQuery对象元素
*/
-
+
editormd.markdownToCRenderer = function(toc, container, tocDropdown, startLevel) {
-
- var html = "";
+
+ var html = "";
var lastLevel = 0;
var classPrefix = this.classPrefix;
-
+
startLevel = startLevel || 1;
-
- for (var i = 0, len = toc.length; i < len; i++)
+
+ for (var i = 0, len = toc.length; i < len; i++)
{
var text = toc[i].text;
var level = toc[i].level;
-
+
if (level < startLevel) {
continue;
}
-
- if (level > lastLevel)
+
+ if (level > lastLevel)
{
html += "";
}
- else if (level < lastLevel)
+ else if (level < lastLevel)
{
html += (new Array(lastLevel - level + 2)).join("");
- }
- else
+ }
+ else
{
html += "";
}
@@ -3857,44 +3870,44 @@
html += "" + text + "";
lastLevel = level;
}
-
+
var tocContainer = container.find(".markdown-toc");
-
+
if ((tocContainer.length < 1 && container.attr("previewContainer") === "false"))
{
var tocHTML = "";
-
+
tocHTML = (tocDropdown) ? "" + tocHTML + "
" : tocHTML;
-
+
container.html(tocHTML);
-
+
tocContainer = container.find(".markdown-toc");
}
-
+
if (tocDropdown)
{
tocContainer.wrap("
");
}
-
+
tocContainer.html("").children(".markdown-toc-list").html(html.replace(/\r?\n?\