From 765564b6dd08b9c3f6ee34b14fe2c4c5e3d7b557 Mon Sep 17 00:00:00 2001 From: yangjian Date: Sun, 31 Jan 2021 13:54:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eeditor.md=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E7=9A=84=E6=96=87=E6=9C=AC=E9=AB=98=E4=BA=AE=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E8=AF=AD=E6=B3=95=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/editor.md/editormd.js | 46 ++++++++++++++++--- template/app_doc/docs_base.html | 6 ++- template/app_doc/editor/create_base.html | 3 +- .../app_doc/editor/tpl_editor_editormd.html | 2 +- template/app_doc/tag_doc_base.html | 2 +- 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/static/editor.md/editormd.js b/static/editor.md/editormd.js index 0ffd853..4ab7bd7 100644 --- a/static/editor.md/editormd.js +++ b/static/editor.md/editormd.js @@ -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 ? "
  • " : "
  • "; @@ -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 "" + e.replace(mark_replace_reg,function($1,$2){return $2}) + "" + }) + } + return text + }; + // marked 链接解析 markedRenderer.link = function (href, title, text) { @@ -3795,7 +3827,7 @@ // headingHTML += ""; headingHTML += "]*>\s?/g,'') + "\" class=\"reference-link\">"; headingHTML += ""; - 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 += ""; return headingHTML; @@ -3832,7 +3864,7 @@ var tocHTML = "
    " + text + "
    "; return (isToC) ? ( (isToCMenu) ? "
    " + tocHTML + "

    " : tocHTML ) - : ( (pageBreakReg.test(text)) ? this.pageBreak(text) : "" + this.atLink(this.emoji(text)) + "

    \n" ); + : ( (pageBreakReg.test(text)) ? this.pageBreak(text) : "" + this.atLink(this.mark(this.emoji(text))) + "

    \n" ); }; // marked 解析代码块 markedRenderer.code = function (code, lang, escaped) { @@ -3887,7 +3919,7 @@ return ""+code+""; } - 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; diff --git a/template/app_doc/docs_base.html b/template/app_doc/docs_base.html index 1057aeb..96fd02a 100644 --- a/template/app_doc/docs_base.html +++ b/template/app_doc/docs_base.html @@ -8,7 +8,7 @@ - + @@ -29,6 +29,9 @@ max-width: 350px; } {% endif %} + /* html{ + filter: invert(1) hue-rotate(180deg); + } */ - {% elif editor_mode == 2 %} diff --git a/template/app_doc/editor/tpl_editor_editormd.html b/template/app_doc/editor/tpl_editor_editormd.html index 90607ef..1bf42ed 100644 --- a/template/app_doc/editor/tpl_editor_editormd.html +++ b/template/app_doc/editor/tpl_editor_editormd.html @@ -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", diff --git a/template/app_doc/tag_doc_base.html b/template/app_doc/tag_doc_base.html index e25af6d..64768a7 100644 --- a/template/app_doc/tag_doc_base.html +++ b/template/app_doc/tag_doc_base.html @@ -21,7 +21,7 @@ - +