-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackquote_highlight.min.js
1 lines (1 loc) · 1.14 KB
/
backquote_highlight.min.js
1
function bq_highlight(){highlight_codeblock_with_prism();for(var e=$("div.tt_article_useless_p_margin p, div.tt_article_useless_p_margin li, div.tt_article_useless_p_margin div:not(:has(div,p))"),i=/``(?:([0-9a-z\-]*)(\s|(?: )))?(.*?)``/g,n=0,r=e.length;n<r;n++)if(e[n].innerText.startsWith("```")){for(var t=n+1;t<r;t++)if(e[t].innerText.startsWith("```")){block_highlight(e,n,t),n=t;break}}else for(var a=e[n].innerHTML,l=i.exec(a),s="",c="";l;){s=l[1]?l[1].substr(0,12):"",""===l[3]?(console.log("``lang `` is invalid syntax"),c=l[1]):c=l[3];var o='<code class="language-'+s+'">'+c+"</code>";e[n].innerHTML=e[n].innerHTML.replace(l[0],o),l=i.exec(a)}}function block_highlight(e,i,n){for(var r=e[i].innerText.substr(3,15),t=$('<div><pre><code class="language-'+r+'"></code></pre></div>'),a=$(t).children().children(),l=i+1;l<n;l++)a.append("<br>"===e[l].innerHTML?"\n":e[l].innerHTML+"\n"),$(e[l]).remove();$(e[i]).after(t),$(e[i]).remove(),$(e[n]).remove()}function highlight_codeblock_with_prism(){const e=$("article pre:has(code)[data-ke-language]");for(let i of e){const e=i.getAttribute("data-ke-language");$(i).children("code").addClass("language-"+e)}}