添加按钮
参照下方文件的格式,根据您自己的源文件内的按钮变量名、格式添加文件末尾的按钮代码。需要修改的文件路径: /vendor/flarum/markdown/js/dist/forum.js
(这里示例代码的 变量可能跟您的源文件不同,请参照实例格式自行修改)。
module.exports=function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=5)}([function(t,e){t.exports=flarum.core.compat.extend},function(t,e){t.exports=flarum.core.compat["components/TextEditor"]},function(t,e){t.exports=flarum.core.compat.Component},function(t,e,n){var i,r,l;"undefined"!=typeof self&&self,r=[],void 0===(l="function"==typeof(i=function(){var t=/mac|iphone|ipad|ipod/i.test(navigator.platform)?"metaKey":"ctrlKey",e=/[*_]/,n=/^[ \t]*(?:(?:[-+*]|\d+\.)[ \t]+(?:\[[ x]][ \t]+)?|>[ \t]*)*(?::[ \t]*)?/,i=/[-=\s"'`<>\[\](){}+*^$\\.|]$/,r=/(?:[-+*]|\d+\.)[ \t]+(?:\[[ x]][ \t]+)?$/,l=/^(?:\n|$)/,o=/[-+*\[\]x\d.]/g,s=/[^ \t]/g,a=/(\d+)\.(?=[ \t]+$)/,c=/(?:(?:^[ \t]+)?(?:[-+*]|\d+\.|[>:])(?:[ \t]+\[[ x]])?[ \t]*|^[ \t]+)$/,u=/^(?!$)/gm,f={"`":/^``$/m,"~":/^~~$/m},h={"[":"]","(":")","{":"}","<":">"},d={"]":"[",")":"(","}":"{",">":"<"},p={enter:["Enter","Shift+Enter"],indent:["Tab","Cmd+m"],outdent:["Shift+Tab","Cmd+Shift+m"],inline:['"',"'","`","*","_","[","]","(",")","{","}","<",">"]};function m(t,e){var n,i;this._options=((n=e)||(n={}),n.keyMap=function(t){t||(t={});var e={},n=[];for(var i in p)if(p.hasOwnProperty(i)){var r=t[i]||p[i];Array.isArray(r)||(r=r.toString().trim().split(/\s*[|,]\s*/g)),n.push.apply(n,r.map((function(t){return(t=v(t)).key in e||(e[t.key]=0),++e[t.key],{key:t,action:i}})))}return n.forEach((function(t){var n;1<e[t.key.key]&&("ctrlKey"in(n=t.key)||(n.ctrlKey=!1),"altKey"in n||(n.altKey=!1),"shiftKey"in n||(n.shiftKey=!1),"metaKey"in n||(n.metaKey=!1))})),n}(n.keyMap),n.indent=("number"!=typeof(i=n.indent||4)&&(i=(i+"").length),new Array(i+1).join(" ")),n),this._reOutdent=new RegExp("^"+this._options.indent,"mg"),this._handleKey=this._handleKey.bind(this),this.setElement(t)}function v(e){var n={};return e.trim().split(/\s*\+\s*/g).forEach((function(e){switch(e.toLowerCase()){case"cmd":n[t]=!0;break;case"ctrl":case"alt":case"shift":case"meta":n[e.toLowerCase()+"Key"]=!0;break;default:n.key=e}})),n}function y(t,e,n,i){if(t.value=e,t.selectionStart=n,t.selectionEnd=3<arguments.length?i:n,"InputEvent"in window)try{var r=new InputEvent("input");t.dispatchEvent(r)}catch(i){}}function g(t,e){return t.replace(e?s:o," ")}return m.prototype={constructor:m,getElement:function(){return this._elem},setElement:function(t){this._elem&&this._elem.removeEventListener("keydown",this._handleKey),(this._elem=t).addEventListener("keydown",this._handleKey)},getValue:function(){return this._elem.value},setValue:function(t){this._elem.value=t},destroy:function(){this._elem.removeEventListener("keydown",this._handleKey),this._elem=this._options=this._reOutdent=this._handleKey=null},_handleKey:function(t){if(!t.defaultPrevented){var o=this._options.keyMap.find((function(e){return function(t,e){for(var n in e)if(e.hasOwnProperty(n)&&t[n]!==e[n])return!1;return!0}(t,e.key)}));if(o){var s=this._elem.value.substring(0,this._elem.selectionStart),p=this._elem.value.substring(this._elem.selectionStart,this._elem.selectionEnd),m=this._elem.value.substring(this._elem.selectionEnd);switch(o.action){case"enter":!function(t,e,i,o,s,u){var f,d,p,m,v,x=i?null:(d=(f=e).lastIndexOf("\n")+1,{line:p=f.substring(d),offset:d,prefix:(m=n.exec(p))&&m[0]});if(i)e+="\n";else if(x.line&&x.line.charAt(x.line.length-1)in h){var b=x.prefix?g(x.prefix,!0):"";o="\n"+b+o,u||(e+="\n"+b+s)}else x.prefix?!u&&x.prefix===x.line&&l.test(o)?e=e.substring(0,x.offset)+x.prefix.replace(c,""):!u&&(v=x.prefix,r.test(v))?e+="\n"+x.prefix.replace(a,(function(t,e){return parseInt(e)+1+"."})):e+="\n"+g(x.prefix,u):e+="\n";y(t,e+o,e.length)}(this._elem,s,p,m,this._options.indent,t.shiftKey);break;case"indent":!function(t,e,n,i,r){var l=e.length,o=e.lastIndexOf("\n")+1;o<l&&(n=e.substring(o)+n,e=e.substring(0,o)),(o<l||!n)&&(l+=r.length),n?n=n.replace(u,r):e+=r,y(t,e+n+i,l,n?o+n.length:l)}(this._elem,s,p,m,this._options.indent);break;case"outdent":!function(t,e,n,i,r,l){var o=e.length,s=e.lastIndexOf("\n")+1;s<o&&(n=e.substring(s)+n,e=e.substring(0,s),n.substring(0,r.length)===r&&(o-=r.length)),y(t,e+(n=n.replace(l,""))+i,o,s+n.length)}(this._elem,s,p,m,this._options.indent,this._reOutdent);break;case"inline":v=this._elem,x=s,b=p,k=m,E=t.key,b||E in h||k.charAt(0)!==E?b||("'"!==E||i.test(x))&&!(E in d)?!b&&E in f&&f[E].test(x)?y(v,x+E+"language\n"+E+E+E+("\n"!==k.charAt(0)?"\n":"")+k,x.length+1,x.length+9):E===x.slice(-1)&&E===k.slice(0,1)?y(v,x.slice(0,-1)+b+k.slice(1),x.length-1,x.length-1+b.length):y(v,x+(d[E]||E)+b+(h[E]||E)+k,x.length+1,x.length+1+b.length):y(v,x+E+k,x.length+1):y(v,x+(e.test(E)?E+E:"")+k,x.length+1)}t.preventDefault()}}var v,x,b,k,E}},m})?i.apply(e,r):i)||(t.exports=l)},function(t,e){t.exports=flarum.core.compat["helpers/icon"]},function(t,e,n){"use strict";n.r(e);var i=n(0),r=n(1),l=n.n(r),o=n(3),s=n.n(o);function a(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var c=n(2),u=n.n(c),f=navigator.userAgent.match(/Macintosh/)?"Meta":"Control",h=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var n=e.prototype;return n.oncreate=function(e){t.prototype.oncreate.call(this,e),document.getElementById(this.attrs.for).addEventListener("keydown",this.shortcut.bind(this))},n.view=function(t){return m("div",{id:"MarkdownToolbar","data-for":this.attrs.for,style:{display:"inline-block"}},t.children)},n.shortcut=function(t){if(t.metaKey&&"Meta"===f||t.ctrlKey&&"Control"===f){var e=this.element.querySelector('[data-hotkey="'+t.key+'"]');e&&(e.click(),t.preventDefault())}},e}(u.a),d=n(4),p=n.n(d);function v(){return(v=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var y=null;function g(t){return t.trim().split("\n").length>1}function x(t,e){return Array(e+1).join(t)}function b(t,e){for(var n=e;t[n]&&null!=t[n-1]&&!t[n-1].match(/\s/);)n--;return n}function k(t,e,n){for(var i=e,r=n?/\n/:/\s/;t[i]&&!t[i].match(r);)i++;return i}function E(t){var e,n,i=t.value.slice(0,t.selectionStart),r=t.value.slice(t.selectionEnd),l=i.match(/\n*$/),o=r.match(/^\n*/),s=l?l[0].length:0,a=o?o[0].length:0;return i.match(/\S/)&&s<2&&(e=x("\n",2-s)),r.match(/\S/)&&a<2&&(n=x("\n",2-a)),null==e&&(e=""),null==n&&(n=""),{newlinesToAppend:e,newlinesToPrepend:n}}var S=function(t,e){var n=e.prefix,i=e.suffix,r=e.blockPrefix,l=e.blockSuffix,o=e.replaceNext,s=e.prefixSpace,a=e.scanFor,c=e.surroundWithNewlines,u=t.selectionStart,f=t.selectionEnd,h=t.value.slice(t.selectionStart,t.selectionEnd),d=g(h)&&r.length>0?r+"\n":n,p=g(h)&&l.length>0?"\n"+l:i;if(s){var m=t.value[t.selectionStart-1];0===t.selectionStart||null==m||m.match(/\s/)||(d=" "+d)}h=function(t,e,n){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(t.selectionStart===t.selectionEnd)t.selectionStart=b(t.value,t.selectionStart),t.selectionEnd=k(t.value,t.selectionEnd,i);else{var r=t.selectionStart-e.length,l=t.selectionEnd+n.length,o=t.value.slice(r,t.selectionStart)===e,s=t.value.slice(t.selectionEnd,l)===n;o&&s&&(t.selectionStart=r,t.selectionEnd=l)}return t.value.slice(t.selectionStart,t.selectionEnd)}(t,d,p,e.multiline);var v=t.selectionStart,y=t.selectionEnd,x=o.length>0&&p.indexOf(o)>-1&&h.length>0;if(c){var S=E(t);d=S.newlinesToAppend+n,p+=S.newlinesToPrepend}if(h.startsWith(d)&&h.endsWith(p)){var _=h.slice(d.length,h.length-p.length);if(u===f){var w=u-d.length;w=Math.max(w,v),v=y=w=Math.min(w,v+_.length)}else y=v+_.length;return{text:_,selectionStart:v,selectionEnd:y}}if(x)return a.length>0&&h.match(a)?{text:d+(p=p.replace(o,h)),selectionStart:v=y=v+d.length,selectionEnd:y}:{text:d+h+p,selectionStart:v=v+d.length+h.length+p.indexOf(o),selectionEnd:y=v+o.length};var O=d+h+p;v=u+d.length,y=f+d.length;var j=h.match(/^\s*|\s*$/g);if(e.trimFirst&&j){var K=j[0]||"",M=j[1]||"";O=K+d+h.trim()+p+M,v+=K.length,y-=M.length}return{text:O,selectionStart:v,selectionEnd:y}},_=function(t,e){var n,i=t.value.slice(t.selectionStart,t.selectionEnd);n=e.orderedList?function(t){var e,n,i,r,l=/^\d+\.\s+/,o=t.selectionStart===t.selectionEnd,s=t.value.slice(t.selectionStart,t.selectionEnd),a=s,c=s.split("\n");if(o){var u=t.value.slice(0,t.selectionStart).split(/\n/);i=t.selectionStart-u[u.length-1].length,r=k(t.value,t.selectionStart,!0),a=t.value.slice(i,r)}var f=a.split("\n");if(f.every((function(t){return l.test(t)}))){if(s=(c=f.map((function(t){return t.replace(l,"")}))).join("\n"),o&&i&&r){var h=f[0].length-c[0].length;n=e=t.selectionStart-h,t.selectionStart=i,t.selectionEnd=r}}else{s=(c=function(){var t,e,n,i=[];for(n=t=0,e=c.length;t<e;n=++t){var r=c[n];i.push(n+1+". "+r)}return i}()).join("\n");var d=E(t),p=d.newlinesToAppend,m=d.newlinesToPrepend;e=(n=t.selectionStart+p.length)+s.length,o&&(n=e),s=p+s+m}return{text:s,selectionStart:n,selectionEnd:e}}(t):e.multiline&&g(i)?function(t,e){var n=e.prefix,i=e.suffix,r=e.surroundWithNewlines,l=t.value.slice(t.selectionStart,t.selectionEnd),o=t.selectionStart,s=t.selectionEnd,a=l.split("\n");if(a.every((function(t){return t.startsWith(n)&&t.endsWith(i)})))s=o+(l=a.map((function(t){return t.slice(n.length,t.length-i.length)})).join("\n")).length;else if(l=a.map((function(t){return n+t+i})).join("\n"),r){var c=E(t),u=c.newlinesToAppend,f=c.newlinesToPrepend;s=(o+=u.length)+l.length,l=u+l+f}return{text:l,selectionStart:o,selectionEnd:s}}(t,e):S(t,e),function(t,e){var n=e.text,i=e.selectionStart,r=e.selectionEnd,l=t.selectionStart,o=t.value.slice(0,l),s=t.value.slice(t.selectionEnd);if(null===y||!0===y){t.contentEditable="true";try{y=document.execCommand("insertText",!1,n)}catch(t){y=!1}t.contentEditable="false"}if(y&&!t.value.slice(0,t.selectionStart).endsWith(n)&&(y=!1),!y){try{document.execCommand("ms-beginUndoUnit")}catch(t){}t.value=o+n+s;try{document.execCommand("ms-endUndoUnit")}catch(t){}var a=document.createEvent("Event");a.initEvent("input",!0,!0),t.dispatchEvent(a)}null!=i&&null!=r?t.setSelectionRange(i,r):t.setSelectionRange(l,t.selectionEnd)}(t,n)},w=navigator.userAgent.match(/Macintosh/)?"⌘":"ctrl",O=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var n=e.prototype;return n.oncreate=function(e){t.prototype.oncreate.call(this,e),this.$().tooltip()},n.view=function(){return m("button",{className:"Button Button--icon Button--link",title:this.title(),"data-hotkey":this.attrs.hotkey,onclick:this.click.bind(this),onkeydown:this.keydown.bind(this)},p()(this.attrs.icon))},n.keydown=function(t){" "!==t.key&&"Enter"!==t.key||(t.preventDefault(),this.click())},n.click=function(){return t=this.element,e=this.attrs.style,n=t.parentElement,i=v({},{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,trimFirst:!1},e),void((r=document.getElementById(n.dataset.for))&&(r.focus(),_(r,i)));var t,e,n,i,r},n.title=function(){var t=this.attrs.title;return this.attrs.hotkey&&(t+=" <"+w+"-"+this.attrs.hotkey+">"),t},e}(u.a);
/*!
* Includes modified code from GitHub Markdown Toolbar Element
* https://github.com/github/markdown-toolbar-element/
*
* Original Copyright GitHub, Inc.
* Released under the MIT license
* https://github.com/github/markdown-toolbar-element/blob/master/LICENSE
*/
app.initializers.add("flarum-markdown",(function(t){var e=1;Object(i.extend)(l.a.prototype,"oninit",(function(){this.textareaId="textarea"+e++})),Object(i.extend)(l.a.prototype,"view",(function(t){t.children[0].attrs.id=this.textareaId})),Object(i.extend)(l.a.prototype,"oncreate",(function(){this.editor=new s.a(this.$("textarea")[0],{keyMap:{indent:["Ctrl+m"],outdent:["Ctrl+M"]}})})),Object(i.extend)(l.a.prototype,"onremove",(function(){this.editor.destroy()})),Object(i.extend)(l.a.prototype,"toolbarItems",(function(e){var n=function(e){return t.translator.trans("flarum-markdown.forum.composer."+e+"_tooltip")};e.add("markdown",m(h,{for:this.textareaId},
m(O,{title:n("header"),icon:"fas fa-heading",style:{prefix:"### "},hotkey:"g"}),
m(O,{title:n("bold"),icon:"fas fa-bold",style:{prefix:"**",suffix:"**",trimFirst:!0},hotkey:"b"}),
m(O,{title:n("italic"),icon:"fas fa-italic",style:{prefix:"_",suffix:"_",trimFirst:!0},hotkey:"i"}),
m(O,{title:n("textsize"),icon:"fas fa-text-height",style:{prefix: '[size=15]', suffix: '[/size]'}}),
m(O,{title:n("underline"),icon:"fas fa-underline",style:{prefix: '[u]', suffix: '[/u]'},hotkey:"u"}),
m(O,{title:n("deleteline"),icon:"fas fa-strikethrough",style:{prefix: '~~', suffix: '~~'},hotkey:"s"}),
m(O,{title:n("highlight"),icon:"fas fa-highlighter",style:{prefix: '[hl]', suffix: '[/hl]'}}),
m(O,{title:n("newline"),icon:"fab fa-stack-exchange",style:{prefix: '***' }}),
m(O,{title:n("textcolor"),icon:"fas fa-tint",style:{prefix: '[color=#536D92]', suffix: '[/color]'}}),
m(O,{title:n("hide"),icon:"fas fa-eye-slash",style:{prefix: '[steam]', suffix: '[/steam]'}}),
m(O,{title:n("quote"),icon:"fas fa-quote-left",style:{prefix:"> ",multiline:!0,surroundWithNewlines:!0}}),
m(O,{title:n("code"),icon:"fas fa-file-code",style:{prefix:"```",suffix:"```",blockPrefix:"```",blockSuffix:"```",trimFirst:!0},hotkey:"d"}),
m(O,{title:n("codebeauty"),icon:"fas fa-code",style:{prefix:"[code]",suffix:"[/code]" }}),
m(O,{title:n("link"),icon:"fas fa-link",style:{prefix:"[链接说明",suffix:"](链接地址)",replaceNext:"https://",scanFor:"https?://"}}),m(O,{title:n("external-link"),icon:"fas fa-external-link-alt",style:{prefix:"[链接说明",suffix:"](链接地址)[ext]",replaceNext:"https://",scanFor:"https?://"},hotkey:"o"}),
m(O,{title:n("image"),icon:"fas fa-image",style:{prefix:"![图片说明",suffix:"](图片地址)",replaceNext:"https://",scanFor:"https?://"}}),
m(O,{title:n("accordion"),icon:"fas fa-folder-open",style:{prefix: '[accordion header="折叠栏标题"]', suffix: '[/accordion]'}}),
m(O,{title:n("shadow"),icon:"fas fa-bars",style:{prefix: '[blur]', suffix: '[/blur]'}}),
m(O,{title:n("center"),icon:"fas fa-align-center",style:{prefix: '[center]', suffix: '[/center]'}}),
m(O,{title:n("unordered_list"),icon:"fas fa-list-alt",style:{prefix:"- ",multiline:!0,surroundWithNewlines:!0}}),
m(O,{title:n("ordered_list"),icon:"fas fa-list-ol",style:{prefix:"1. ",multiline:!0,orderedList:!0,surroundWithNewlines:!0}}),
m(O,{title:n("login"),icon:"fas fa-sign-in-alt",style:{prefix: '[login]', suffix: '[/login]'}}),),100)}))}))}]);
//# sourceMappingURL=forum.js.map
按钮代码构成:
按钮名 图标代码 前缀 后缀 去除首尾字符 快捷键
m(O,{title:n("codebox"),icon:"fas fa-file-code",style:{prefix:"```",suffix:"\n```",trimFirst:!0},hotkey:"d"}),
根据自己的需求更改吧~