新增editor.md编辑器的文本高亮标记语法支持
This commit is contained in:
parent
34f176ded7
commit
765564b6dd
@ -194,6 +194,7 @@
|
||||
"undo" : "fa-undo",
|
||||
"redo" : "fa-repeat",
|
||||
"bold" : "fa-bold",
|
||||
"mark" : "fa-paint-brush",
|
||||
"del" : "fa-strikethrough",
|
||||
"italic" : "fa-italic",
|
||||
"quote" : "fa-quote-left",
|
||||
@ -204,8 +205,8 @@
|
||||
"h4" : editormd.classPrefix + "bold",
|
||||
"h5" : editormd.classPrefix + "bold",
|
||||
"h6" : editormd.classPrefix + "bold",
|
||||
"list-ul" : "fa-list-ul",
|
||||
"list-ol" : "fa-list-ol",
|
||||
"list-ul" : "fa-list-ul",
|
||||
"list-ol" : "fa-list-ol",
|
||||
"hr" : "fa-minus",
|
||||
"link" : "fa-link",
|
||||
"reference-link" : "fa-anchor",
|
||||
@ -229,6 +230,7 @@
|
||||
"info" : "fa-info-circle"
|
||||
},
|
||||
toolbarIconTexts : {},
|
||||
toolbarIconSvgs : {},
|
||||
|
||||
lang : {
|
||||
name : "zh-cn",
|
||||
@ -238,6 +240,7 @@
|
||||
undo : "撤销(Ctrl+Z)",
|
||||
redo : "重做(Ctrl+Y)",
|
||||
bold : "粗体",
|
||||
mark : "文本高亮",
|
||||
del : "删除线",
|
||||
italic : "斜体",
|
||||
quote : "引用",
|
||||
@ -1207,10 +1210,12 @@
|
||||
|
||||
var title = settings.lang.toolbar[index];
|
||||
var iconTexts = settings.toolbarIconTexts[index];
|
||||
var iconSvgs = settings.toolbarIconSvgs[index];
|
||||
var iconClass = settings.toolbarIconsClass[index];
|
||||
|
||||
title = (typeof title === "undefined") ? "" : title;
|
||||
iconTexts = (typeof iconTexts === "undefined") ? "" : iconTexts;
|
||||
iconSvgs = (typeof iconSvgs === "undefined") ? "" : iconSvgs;
|
||||
iconClass = (typeof iconClass === "undefined") ? "" : iconClass;
|
||||
|
||||
var menuItem = pullRight ? "<li class=\"pull-right\">" : "<li>";
|
||||
@ -2928,6 +2933,19 @@
|
||||
cm.setCursor(cursor.line, cursor.ch + 2);
|
||||
}
|
||||
},
|
||||
|
||||
mark : function(){
|
||||
var cm = this.cm;
|
||||
var cursor = cm.getCursor();
|
||||
var selection = cm.getSelection();
|
||||
|
||||
cm.replaceSelection("==" + selection + "==");
|
||||
|
||||
if(selection === "") {
|
||||
cm.setCursor(cursor.line, cursor.ch + 2);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
del : function() {
|
||||
var cm = this.cm;
|
||||
@ -3454,7 +3472,7 @@
|
||||
atLink : /@(\w+)/g,
|
||||
email : /(\w+)@(\w+)\.(\w+)\.?(\w+)?/g,
|
||||
emailLink : /(mailto:)?([\w\.\_]+)@(\w+)\.(\w+)\.?(\w+)?/g,
|
||||
//emoji : /:([\w\+-]+):/g,
|
||||
mark : /==([^\s=])==(?!=)|==([^\s=])==(?!=)|==([^\s][\s\S]*?[^\s])==(?!=)|==([^\s][\s\S]*?[^\s])==(?!=)/g,
|
||||
emoji : /:([A-Za-z\+-]+):/g,
|
||||
emojiDatetime : /(\d{2}:\d{2}:\d{2})/g,
|
||||
twemoji : /:(tw-([\w]+)-?(\w+)?):/g,
|
||||
@ -3465,7 +3483,6 @@
|
||||
|
||||
// Emoji graphics files url path
|
||||
editormd.emoji = {
|
||||
//path : "http://www.emoji-cheat-sheet.com/graphics/emojis/",
|
||||
path : "/static/editor.md/plugins/emoji-dialog/emoji/",
|
||||
ext : ".png"
|
||||
};
|
||||
@ -3506,6 +3523,7 @@
|
||||
|
||||
var regexs = editormd.regexs;
|
||||
var atLinkReg = regexs.atLink;
|
||||
var markReg = regexs.mark;
|
||||
var emojiReg = regexs.emoji;
|
||||
var emailReg = regexs.email;
|
||||
var emailLinkReg = regexs.emailLink;
|
||||
@ -3718,6 +3736,20 @@
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
// marked 高亮标记解析
|
||||
markedRenderer.mark = function(text){
|
||||
if(markReg.test(text)){
|
||||
// console.log(text)
|
||||
var mark_replace_reg = /==(.+)==/g
|
||||
text = text.replace(markReg,function(e){
|
||||
// console.log(e)
|
||||
return "<mark>" + e.replace(mark_replace_reg,function($1,$2){return $2}) + "</mark>"
|
||||
})
|
||||
}
|
||||
return text
|
||||
};
|
||||
|
||||
// marked 链接解析
|
||||
markedRenderer.link = function (href, title, text) {
|
||||
|
||||
@ -3795,7 +3827,7 @@
|
||||
// headingHTML += "<a name=\"" + text + "\" class=\"reference-link\"></a>";
|
||||
headingHTML += "<a name=\"" + text.replace(/<[^>]*>\s?/g,'') + "\" class=\"reference-link\"></a>";
|
||||
headingHTML += "<span class=\"header-link octicon octicon-link\"></span>";
|
||||
headingHTML += (hasLinkReg) ? this.atLink(this.emoji(linkText)) : this.atLink(this.emoji(text));
|
||||
headingHTML += (hasLinkReg) ? this.atLink(this.mark(this.emoji(text))) : this.mark(this.emoji(text));
|
||||
headingHTML += "</h" + level + ">";
|
||||
|
||||
return headingHTML;
|
||||
@ -3832,7 +3864,7 @@
|
||||
var tocHTML = "<div class=\"markdown-toc editormd-markdown-toc\">" + text + "</div>";
|
||||
|
||||
return (isToC) ? ( (isToCMenu) ? "<div class=\"editormd-toc-menu\">" + tocHTML + "</div><br/>" : tocHTML )
|
||||
: ( (pageBreakReg.test(text)) ? this.pageBreak(text) : "<p" + isTeXAddClass + ">" + this.atLink(this.emoji(text)) + "</p>\n" );
|
||||
: ( (pageBreakReg.test(text)) ? this.pageBreak(text) : "<p" + isTeXAddClass + ">" + this.atLink(this.mark(this.emoji(text))) + "</p>\n" );
|
||||
};
|
||||
// marked 解析代码块
|
||||
markedRenderer.code = function (code, lang, escaped) {
|
||||
@ -3887,7 +3919,7 @@
|
||||
|
||||
return "<svg class='mindmap' style='width:100%;min-height:150px;height:"+ custom_height +"px;' id='mindmap-"+ map_id +"'>"+code+"</svg>";
|
||||
}
|
||||
else if(/^echart/i.test(lang)){ // echart 图表
|
||||
else if(/^echart/i.test(lang)||/^echarts/i.test(lang)){ // echart 图表
|
||||
var len = 9 || 32;
|
||||
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
|
||||
var maxPos = $chars.length;
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
<meta http-equiv="Cache-Control" content="no-transform" />
|
||||
<meta http-equiv="Cache-Control" content="no-siteapp" />
|
||||
<meta http-equiv="Cache-Control" content="max-age=7200" />
|
||||
<meta name="referrer" content="strict-origin">
|
||||
<meta name="referrer" content="no-referrer">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta name="keywords" content="{% block keyword %}{% endblock %}{{site_keywords}}"/>
|
||||
<meta name="description" content="{% block description %}{% endblock %}" />
|
||||
@ -29,6 +29,9 @@
|
||||
max-width: 350px;
|
||||
}
|
||||
{% endif %}
|
||||
/* html{
|
||||
filter: invert(1) hue-rotate(180deg);
|
||||
} */
|
||||
</style>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
||||
@ -329,7 +332,6 @@
|
||||
// EditorMD模式
|
||||
//解析Markdown为HTML
|
||||
editormd.markdownToHTML("content", {
|
||||
htmlDecode : "style,script,iframe",
|
||||
emoji : true, //emoji表情
|
||||
taskList : true, // 任务列表
|
||||
tex : true, // 科学公式
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
<meta http-equiv="Cache-Control" content="no-transform" />
|
||||
<meta http-equiv="Cache-Control" content="no-siteapp" />
|
||||
<meta http-equiv="Cache-Control" content="max-age=7200" />
|
||||
<meta name="referrer" content="strict-origin">
|
||||
<meta name="referrer" content="no-referrer">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<title>{% block title %}{% endblock %} - {% if site_name != None and site_name != '' %}{{site_name}} {% else %}站点标题{% endif %}</title>
|
||||
<link href="{% static 'layui/css/layui.css' %}?version={{mrdoc_version}}" rel="stylesheet">
|
||||
@ -16,7 +16,6 @@
|
||||
{% if editor_mode == 1 %}
|
||||
<!-- Editor.MD编辑器样式表 -->
|
||||
<link rel="stylesheet" href="{% static 'editor.md/css/editormd.css' %}?version={{mrdoc_version}}" />
|
||||
<link rel="stylesheet" href="{% static 'katex/katex.min.css' %}?version={{mrdoc_version}}" />
|
||||
{% elif editor_mode == 2 %}
|
||||
<!-- Vditor编辑器样式表 -->
|
||||
<link rel="stylesheet" href="{% static 'vditor/dist/index.css' %}?version={{mrdoc_version}}" />
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
var editormd_height = '800px'
|
||||
var editormd_toobar = [
|
||||
"undo", "redo", "|",
|
||||
"h2","h3","h4","h5", "bold", "del", "italic", "quote","kaiSpan",
|
||||
"h2","h3","h4","h5", "bold", "del", "italic", "quote","kaiSpan","mark",
|
||||
"list-ul", "list-ol", "hr", "link", "reference-link",
|
||||
"mindmap","echart","imgUpload", "attachment" ,"multimedia","code", "code-block", "htmltable",
|
||||
"emoji", "html-entities", "pagebreak",
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
<link rel="icon" href="{% static 'search/mrdoc_logo_300.png' %}" sizes="192x192" />
|
||||
<link href="{% static 'mrdoc/mrdoc.css' %}?version={{mrdoc_version}}" rel="stylesheet">
|
||||
<link href="{% static 'mrdoc/mrdoc-docs.css' %}?version={{mrdoc_version}}" rel="stylesheet">
|
||||
|
||||
<link href="{% static 'iconFont/iconfont.css' %}?version={{mrdoc_version}}" rel="stylesheet">
|
||||
<style>
|
||||
{% if img_scale %}
|
||||
.markdown-body p img{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user