mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-25 09:21:04 +00:00
1 line
16 KiB
JavaScript
1 line
16 KiB
JavaScript
|
var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(u){var g=/\blang(?:uage)?-([\w-]+)\b/i,t=0,z={manual:u.Prism&&u.Prism.manual,disableWorkerMessageHandler:u.Prism&&u.Prism.disableWorkerMessageHandler,util:{encode:function e(t){return t instanceof T?new T(t.type,e(t.content),t.alias):Array.isArray(t)?t.map(e):t.replace(/&/g,"&").replace(/</g,"<").replace(/\u00a0/g," ")},type:function(e){return Object.prototype.toString.call(e).slice(8,-1)},objId:function(e){return e.__id||Object.defineProperty(e,"__id",{value:++t}),e.__id},clone:function n(e,a){var r,t;switch(a=a||{},z.util.type(e)){case"Object":if(t=z.util.objId(e),a[t])return a[t];for(var s in r={},a[t]=r,e)e.hasOwnProperty(s)&&(r[s]=n(e[s],a));return r;case"Array":return(t=z.util.objId(e),a[t])?a[t]:(r=[],a[t]=r,e.forEach(function(e,t){r[t]=n(e,a)}),r);default:return e}},getLanguage:function(e){for(;e&&!g.test(e.className);)e=e.parentElement;return e?(e.className.match(g)||[,"none"])[1].toLowerCase():"none"},currentScript:function(){if("undefined"==typeof document)return null;if("currentScript"in document)return document.currentScript;try{throw new Error}catch(e){var t=(/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(e.stack)||[])[1];if(t){var n=document.getElementsByTagName("script");for(var a in n)if(n[a].src==t)return n[a]}return null}},isActive:function(e,t,n){for(var a="no-"+t;e;){var r=e.classList;if(r.contains(t))return!0;if(r.contains(a))return!1;e=e.parentElement}return!!n}},languages:{extend:function(e,t){var n=z.util.clone(z.languages[e]);for(var a in t)n[a]=t[a];return n},insertBefore:function(n,e,t,a){var r=(a=a||z.languages)[n],s={};for(var i in r)if(r.hasOwnProperty(i)){if(i==e)for(var l in t)t.hasOwnProperty(l)&&(s[l]=t[l]);t.hasOwnProperty(i)||(s[i]=r[i])}var o=a[n];return a[n]=s,z.languages.DFS(z.languages,function(e,t){t===o&&e!=n&&(this[e]=s)}),s},DFS:function e(t,n,a,r){r=r||{};var s,i,l=z.util.objId;for(var o in t){t.hasOwnProperty(o)&&(n.call(t,o,t[o],a||o),s=t[o],"Object"!==(i=z.util.type(s))||r[l(s)]?"Array"!==i||r[l(s)]||(r[l(s)]=!0,e(s,n,o,r)):(r[l(s)]=!0,e(s,n,null,r)))}}},plugins:{},highlightAll:function(e,t){z.highlightAllUnder(document,e,t)},highlightAllUnder:function(e,t,n){var a={callback:n,container:e,selector:'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'};z.hooks.run("before-highlightall",a),a.elements=Array.prototype.slice.apply(a.container.querySelectorAll(a.selector)),z.hooks.run("before-all-elements-highlight",a);for(var r,s=0;r=a.elements[s++];)z.highlightElement(r,!0===t,a.callback)},highlightElement:function(e,t,n){var a=z.util.getLanguage(e),r=z.languages[a];e.className=e.className.replace(g,"").replace(/\s+/g," ")+" language-"+a;var s=e.parentElement;s&&"pre"===s.nodeName.toLowerCase()&&(s.className=s.className.replace(g,"").replace(/\s+/g," ")+" language-"+a);var i,l={element:e,language:a,grammar:r,code:e.textContent};function o(e){l.highlightedCode=e,z.hooks.run("before-insert",l),l.element.innerHTML=l.highlightedCode,z.hooks.run("after-highlight",l),z.hooks.run("complete",l),n&&n.call(l.element)}if(z.hooks.run("before-sanity-check",l),!l.code)return z.hooks.run("complete",l),void(n&&n.call(l.element));z.hooks.run("before-highlight",l),l.grammar?t&&u.Worker?((i=new Worker(z.filename)).onmessage=function(e){o(e.data)},i.postMessage(JSON.stringify({language:l.language,code:l.code,immediateClose:!0}))):o(z.highlight(l.code,l.grammar,l.language)):o(z.util.encode(l.code))},highlight:function(e,t,n){var a={code:e,grammar:t,language:n};return z.hooks.run("before-tokenize",a),a.tokens=z.tokenize(a.code,a.grammar),z.hooks.run("after-tokenize",a),T.stringify(z.util.encode(a.tokens),a.language)},tokenize:function(e,t){var n=t.rest;if(n){for(var a in n)t[a]=n[a];delete t.rest}var r=new s;return N(r,r.head,e),function e(t,n,a,r,s,i){for(var l in a)if(a.hasOwnProperty(l)&&a[l]){var o=a[l];o=Array.isArray(o)?o:[o];for(var u=0;u<o.length;++u){if(i&&i.cause==l+","+u)return;var g,c=o[u],d=c.inside,p=!!c.l
|