(self.webpackChunknodebb=self.webpackChunknodebb||[]).push([[61324],{61324:(m,L,v)=>{"use strict";v.r(L),v.d(L,{buildAliasMap:()=>M,capturePaste:()=>B,enhanceCheckbox:()=>x,highlight:()=>A,markExternalLinks:()=>E,prepareFormattingTools:()=>k});function B(s){s.on("paste",function(a){var f=[/^>\s*/,/^\s*\*\s+/,/^\s*\d+\.\s+/,/^\s{4,}/],l=a.target.selectionStart,g=d(s.val(),l),e=f.reduce(function(c,N){return c||(N.test(g)?N:!1)},!1),t=g.match(e);if(t){t=t.shift();var r=a.originalEvent.clipboardData.getData("text"),o=r.replace(/^/gm,t).slice(t.length);setTimeout(function(){var c=s.val().slice(0,l)+o+s.val().slice(l+r.length);s.val(c)},0)}});function d(a,f){var l=a.split(` `);return l.reduce(function(g,e){return typeof g!="number"?g:f>g+e.length?g+e.length+1:e},0)}}function k(){Promise.all([v.e(23662),v.e(65285),v.e(449),v.e(34670)]).then(function(){var s=[v(449),v(26940),v(17459)];(function(d,a,f){d&&a&&f.getTranslations(window.config.userLang||window.config.defaultLang,"markdown",function(l){function g(e,t,r,o){if(r===o)a.insertIntoTextarea(t,`${e} ${l.heading}`),a.updateTextareaSelection(t,r+e.length+1,r+l.heading.length+e.length+1);else{const c=$(t).val().substring(r,o),N=`${e} ${c}`;a.replaceSelectionInTextareaWith(t,N),a.updateTextareaSelection(t,r+(e.length+1),o+(N.length-c.length))}}d.addButtonDispatch("bold",function(e,t,r){if(t===r){var o=a.getBlockData(e,"**",t);o.in&&o.atEnd?a.updateTextareaSelection(e,t+2,t+2):(a.insertIntoTextarea(e,"**"+l.bold+"**"),a.updateTextareaSelection(e,t+2,t+l.bold.length+2))}else{var c=a.wrapSelectionInTextareaWith(e,"**");a.updateTextareaSelection(e,t+2+c[0],r+2-c[1])}}),d.addButtonDispatch("italic",function(e,t,r){if(t===r){var o=a.getBlockData(e,"*",t);o.in&&o.atEnd?a.updateTextareaSelection(e,t+1,t+1):(a.insertIntoTextarea(e,"*"+l.italic+"*"),a.updateTextareaSelection(e,t+1,t+l.italic.length+1))}else{var c=a.wrapSelectionInTextareaWith(e,"*");a.updateTextareaSelection(e,t+1+c[0],r+1-c[1])}}),[1,2,3,4,5,6].forEach(e=>{d.addButtonDispatch(`heading${e}`,function(t,r,o){g(new Array(e).fill("#").join(""),t,r,o)})}),d.addButtonDispatch("list",function(e,t,r){if(t===r)a.insertIntoTextarea(e,` * `+l["list-item"]),a.updateTextareaSelection(e,t+3,t+l["list-item"].length+3);else{const o=$(e).val().substring(t,r),c="* "+o.split(` `).join(` * `);a.replaceSelectionInTextareaWith(e,c),a.updateTextareaSelection(e,t+2,r+(c.length-o.length))}}),d.addButtonDispatch("strikethrough",function(e,t,r){if(t===r){var o=a.getBlockData(e,"~~",t);o.in&&o.atEnd?a.updateTextareaSelection(e,t+2,t+2):(a.insertIntoTextarea(e,"~~"+l["strikethrough-text"]+"~~"),a.updateTextareaSelection(e,t+2,r+l["strikethrough-text"].length+2))}else{var c=a.wrapSelectionInTextareaWith(e,"~~","~~");a.updateTextareaSelection(e,t+2+c[0],r+2-c[1])}}),d.addButtonDispatch("code",function(e,t,r){if(t===r)a.insertIntoTextarea(e,"```\n"+l["code-text"]+"\n```"),a.updateTextareaSelection(e,t+4,r+l["code-text"].length+4);else{var o=a.wrapSelectionInTextareaWith(e,"```\n","\n```");a.updateTextareaSelection(e,t+4+o[0],r+4-o[1])}}),d.addButtonDispatch("link",function(e,t,r){if(t===r)a.insertIntoTextarea(e,"["+l["link-text"]+"]("+l["link-url"]+")"),a.updateTextareaSelection(e,t+l["link-text"].length+3,r+l["link-text"].length+l["link-url"].length+3);else{var o=a.wrapSelectionInTextareaWith(e,"[","]("+l["link-url"]+")");a.updateTextareaSelection(e,r+3-o[1],r+l["link-url"].length+3-o[1])}}),d.addButtonDispatch("picture-o",function(e,t,r){if(t===r)a.insertIntoTextarea(e,"!["+l["picture-text"]+"]("+l["picture-url"]+")"),a.updateTextareaSelection(e,t+l["picture-text"].length+4,r+l["picture-text"].length+l["picture-url"].length+4);else{var o=a.wrapSelectionInTextareaWith(e,"![","]("+l["picture-url"]+")");a.updateTextareaSelection(e,r+4-o[1],r+l["picture-url"].length+4-o[1])}})})}).apply(null,s)}).catch(v.oe)}function E(){if(!config.markdown.externalMark)return;document.querySelectorAll('[component="post/content"] a').forEach(d=>{if(d.childElementCount===1&&d.querySelector("img")&&!d.text)return;if(new URL(d.href,document.location.href).host!=document.location.host){const f=document.createElement("i");f.classList.add("fa","fa-external-link","small"),d.append(" ",f)}})}function x(s,d){if(!(!d.posts&&!d.post)){d.hasOwnProperty("post")&&(d.posts=[d.post]);var a,f;d.posts.forEach(function(l){a=!l.display_edit_tools,f=$('.posts li[data-pid="'+l.pid+'"] .content div.plugin-markdown input[type="checkbox"]'),f.on("click",function(g){a&&g.preventDefault();var e=this,t=$(this).parents("li[data-pid]").attr("data-pid"),r=$(this).parents(".content").find('input[type="checkbox"]').toArray().reduce(function(o,c,N){return c===e&&(o=N),o},null);socket.emit("plugins.markdown.checkbox.edit",{pid:t,index:r,state:$(e).prop("checked")})})})}}function A(s){s instanceof jQuery.Event?I($(s.data.selector)):I(s)}const b=new Map;function M(){if(window.hljs){const s=window.hljs;s.listLanguages().forEach(d=>{const{aliases:a}=s.getLanguage(d);a&&Array.isArray(a)&&a.forEach(f=>{b.set(f,d)}),b.set(d,d)})}}async function I(s){if(parseInt(config.markdown.highlight,10)){if(!window.hljs){console.debug("[plugins/markdown] Tryin to highlight without initializing hljs");return}console.debug("[plugins/markdown] Loading support for line numbers"),v(85079),s.each(function(a,f){const l=$(f.parentNode);if(l.hasClass("markdown-highlight"))return;l.addClass("markdown-highlight"),!Array.prototype.some.call(f.classList,e=>e.startsWith("language-"))&&config.markdown.defaultHighlightLanguage&&f.classList.add(`language-${config.markdown.defaultHighlightLanguage}`),window.hljs.highlightElement(f);const g=f.classList.values();for(const e of g)if(e.startsWith("language-")){const t=e.split("-")[1],r=config.markdown.highlightLinesLanguageList;b.has(t)&&r&&r.includes(b.get(t))&&($(f).attr("data-lines",1),window.hljs.lineNumbersBlock(f));break}})}}},85079:()=>{(function(m,L){"use strict";var v="hljs-ln",B="hljs-ln-line",k="hljs-ln-code",E="hljs-ln-numbers",x="hljs-ln-n",A="data-line-number",b=/\r\n|\r|\n/g;m.hljs?(m.hljs.initLineNumbersOnLoad=a,m.hljs.lineNumbersBlock=g,m.hljs.lineNumbersValue=e,d()):m.console.error("highlight.js not detected!");function M(n){for(var i=n;i;){if(i.className&&i.className.indexOf("hljs-ln-code")!==-1)return!0;i=i.parentNode}return!1}function I(n){for(var i=n;i.nodeName!=="TABLE";)i=i.parentNode;return i}function s(n){for(var i=n.toString(),u=n.anchorNode;u.nodeName!=="TD";)u=u.parentNode;for(var h=n.focusNode;h.nodeName!=="TD";)h=h.parentNode;var p=parseInt(u.dataset.lineNumber),T=parseInt(h.dataset.lineNumber);if(p!=T){var w=u.textContent,y=h.textContent;if(p>T){var C=p;p=T,T=C,C=w,w=y,y=C}for(;i.indexOf(w)!==0;)w=w.slice(1);for(;i.lastIndexOf(y)===-1;)y=y.slice(0,-1);for(var D=w,U=I(u),O=p+1;O1||i.singleLine){for(var h="",p=0,T=u.length;p
{6}',[B,E,x,A,k,p+i.startFrom,u[p].length>0?u[p]:" "]);return j('{1}
',[v,h])}return n}function o(n,i){return i=i||{},{singleLine:c(i),startFrom:N(n,i)}}function c(n){var i=!1;return n.singleLine?n.singleLine:i}function N(n,i){var u=1,h=u;isFinite(i.startFrom)&&(h=i.startFrom);var p=P(n,"data-ln-start-from");return p!==null&&(h=K(p,u)),h}function F(n){var i=n.childNodes;for(var u in i)if(i.hasOwnProperty(u)){var h=i[u];R(h.textContent)>0&&(h.childNodes.length>0?F(h):H(h.parentNode))}}function H(n){var i=n.className;if(/hljs-/.test(i)){for(var u=S(n.innerHTML),h=0,p="";h0?u[h]:" ";p+=j(`{1} `,[i,T])}n.innerHTML=p.trim()}}function S(n){return n.length===0?[]:n.split(b)}function R(n){return(n.trim().match(b)||[]).length}function W(n){m.setTimeout(n,0)}function j(n,i){return n.replace(/\{(\d+)\}/g,function(u,h){return i[h]!==void 0?i[h]:u})}function P(n,i){return n.hasAttribute(i)?n.getAttribute(i):null}function K(n,i){if(!n)return i;var u=Number(n);return isFinite(u)?u:i}})(window,document)}}]);