UNPKG

docsify-latex

Version:

A docsify.js plugin for typesetting LaTeX with display engines from markdown

10 lines (9 loc) 15.9 kB
/*! * docsify-latex * v0.5.2 * https://scruel.github.io/docsify-latex/ * (c) 2022 Scruel Tao * MIT license */ !function(){"use strict";function t(){t=function(){return e};var e={},n=Object.prototype,r=n.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,n){return t[e]=n}}function l(t,e,n,r){var o=e&&e.prototype instanceof h?e:h,a=Object.create(o.prototype),i=new E(r||[]);return a._invoke=function(t,e,n){var r="suspendedStart";return function(o,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw a;return O()}for(n.method=o,n.arg=a;;){var i=n.delegate;if(i){var c=b(i,n);if(c){if(c===s)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var u=f(t,e,n);if("normal"===u.type){if(r=n.done?"completed":"suspendedYield",u.arg===s)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r="completed",n.method="throw",n.arg=u.arg)}}}(t,n,i),a}function f(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var s={};function h(){}function p(){}function d(){}var v={};u(v,a,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(L([])));g&&g!==n&&r.call(g,a)&&(v=g);var m=d.prototype=h.prototype=Object.create(v);function x(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function n(o,a,i,c){var u=f(t[o],t,a);if("throw"!==u.type){var l=u.arg,s=l.value;return s&&"object"==typeof s&&r.call(s,"__await")?e.resolve(s.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(s).then((function(t){l.value=t,i(l)}),(function(t){return n("throw",t,i,c)}))}c(u.arg)}var o;this._invoke=function(t,r){function a(){return new e((function(e,o){n(t,r,e,o)}))}return o=o?o.then(a,a):a()}}function b(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,b(t,e),"throw"===e.method))return s;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var r=f(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,s;var o=r.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,s):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,s)}function M(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function k(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(M,this),this.reset(!0)}function L(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:O}}function O(){return{value:void 0,done:!0}}return p.prototype=d,u(m,"constructor",d),u(d,"constructor",p),p.displayName=u(d,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},e.awrap=function(t){return{__await:t}},x(w.prototype),u(w.prototype,i,(function(){return this})),e.AsyncIterator=w,e.async=function(t,n,r,o,a){void 0===a&&(a=Promise);var i=new w(l(t,n,r,o),a);return e.isGeneratorFunction(n)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},x(m),u(m,c,"Generator"),u(m,a,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=L,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(n,r){return i.type="throw",i.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,s):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),s},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),k(n),s}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;k(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:L(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),s}},e}function e(t,e,n,r,o,a,i){try{var c=t[a](i),u=c.value}catch(t){return void n(t)}c.done?e(u):Promise.resolve(u).then(r,o)}function n(t){return function(){var n=this,r=arguments;return new Promise((function(o,a){var i=t.apply(n,r);function c(t){e(i,o,a,c,u,"next",t)}function u(t){e(i,o,a,c,u,"throw",t)}c(void 0)}))}}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function o(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,a=function(){};return{s:a,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,u=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return c=t.done,t},e:function(t){u=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(u)throw i}}}}function a(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function i(t,e){Object.keys(t).forEach((function(n){Object.prototype.hasOwnProperty.call(e,n)&&"[object Object]"===Object.prototype.toString.call(t[n])?i(t[n],e[n]):e[n]=t[n]}))}var c={inlineMath:[["$","$"],["\\(","\\)"]],displayMath:[["$$","$$"]],overflowScroll:!0,beforeInitFunc:function(){},customOptions:{}};window&&(window.$docsify=window.$docsify||{},window.$docsify.latex=window.$docsify.latex||{},i(window.$docsify.latex,c),window.$docsify.latex.version="0.5.2");var u="docsify-latex",l="docsify-latex-back",f="display",s="#0B87DA";function h(t){var e=t.querySelectorAll("".concat(u," a[href]"));if(null!==e&&0!==e.length){var n,r=o(e);try{var a=function(){var t=n.value;Object.prototype.hasOwnProperty.call(t.style,"color")&&t.style.color||(t.style.color=s);var e=t.getAttribute("href"),r=decodeURIComponent(e).substring(1);e.startsWith("#")&&(t.title="Jump to equation",t.onclick=function(){var e=document.getElementById(r);if(null===e)return!0;for(var n=e.parentElement;null!==n&&n.tagName!==u.toUpperCase();)n=n.parentElement;var o=n.querySelector(l);null===o&&(o=document.createElement(l),n.append(o),o.innerHTML='<a href onclick="return false;">'.concat("Back To Reference","</a>"),o.style.color=s,o.style.float="right");var a=document.documentElement.scrollTop;return o.style.display="",o.onclick=function(){return o.style.display="none",window.scrollTo(0,a),!1},window.scrollTo(0,n.offsetTop-t.getBoundingClientRect().top),!1})};for(r.s();!(n=r.n()).done;)a()}catch(t){r.e(t)}finally{r.f()}}}var p=Object;if(p.prepareContent=function(t,e){return t},p.prepareRender=function(){},p.renderElement=function(t,e){},p.afterRender=function(){},c.beforeInitFunc(),"undefined"!=typeof MathJax&&MathJax){if("3"===MathJax.version[0])i(c.customOptions,MathJax.config),MathJax.config.tex.inlineMath=c.inlineMath,MathJax.config.tex.displayMath=c.displayMath,MathJax.startup.getComponents(),p.prepareRender=function(){MathJax.startup.getComponents();var t=MathJax.startup.output;void 0!==t.clearCache?t.clearCache():void 0!==t.clearFontCache&&t.clearFontCache()},p.renderElement=function(){var e=n(t().mark((function e(n,r){return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,MathJax.typesetPromise([n]);case 2:case"end":return t.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),p.afterRender=function(){if(h(document),c.overflowScroll){var t,e=o(document.querySelectorAll(u));try{for(e.s();!(t=e.n()).done;){var n=t.value,r=n.querySelector("mjx-math");if(null!==r){r.style.width="";var a=r.getBoundingClientRect().width,i=0,l=n.querySelector("mjx-assistive-mml");null!==r&&(i=l.getBoundingClientRect().width),n.style.width=Math.max(a,i)+"px"}}}catch(t){e.e(t)}finally{e.f()}}};else if("2"===MathJax.version[0]){var d={skipStartupTypeset:!0,messageStyle:"none"};i(c.customOptions,d),i({tex2jax:{inlineMath:c.inlineMath,displayMath:c.displayMath}},d),MathJax.Hub.Config(d),MathJax.Hub.processSectionDelay=0,MathJax.Hub.processUpdateDelay=0,p.prepareRender=function(){void 0!==MathJax.InputJax.TeX&&MathJax.Hub.Queue(["PreProcess",MathJax.Hub],["resetEquationNumbers",MathJax.InputJax.TeX]),MathJax.Hub.Queue(["PreProcess",MathJax.Hub],["Reprocess",MathJax.Hub])},p.renderElement=function(t,e){MathJax.Hub.Queue(["Typeset",MathJax.Hub,t],[h,t])}}}else if("undefined"!=typeof katex&&katex){var v={throwOnError:!1,trust:function(t){return["\\htmlId","\\href"].includes(t.command)},macros:{"\\eqref":"\\href{##ktx-#1}{(\\text{#1})}","\\ref":"\\href{##ktx-#1}{\\text{#1}}","\\label":"\\htmlId{ktx-#1}{}"}};i(c.customOptions,v),p.prepareContent=function(t,e){return e},p.renderElement=function(t,e){v.displayMode=e,t.innerHTML=katex.renderToString(t.innerHTML.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&amp;/g,"&"),v),h(t)}}var y="latex:replace",g="latex:delete";function m(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return"\x3c!-- ".concat(y," ").concat(e," ").concat(t," --\x3e")}function x(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return new RegExp("\x3c!-- ".concat(y," ").concat(t," (.*?) --\x3e"))}function w(t,e,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return r&&(t=a(t),e=a(e)),new RegExp("(?:^|[^\\\\])((".concat(t,")((?:[^\\\\").concat(n?"":"\n","]|\\\\.)+?)").concat(e,")"))}function b(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=w(e[0],e[1],n);return M(t,r,n)}function M(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=t.match(e);if(r){var o={};return o.displayMode=n,o.content=r[1],o.innerContent=r[3],o.index=r.index+r[0].length-o.content.length,o.endIndex=o.index+o.content.length,o.regex=e,o}return null}var k="CODE",E={codeTagMarkup:w("<code>","</code>",!0),codeBlockMarkup:w("`{3,}","\\2",!0,!1),codeInlineMarkup:w("`{1,}","\\2",!1,!1),commentDeleteReplaceMarkup:/^(>?[ ]*)<!--/gm,commentReplaceMarkup:x(),commentCodeReplaceMarkup:x(k)};function L(t){var e,n,r,a=[],i=o(c.inlineMath);try{for(i.s();!(r=i.n()).done;){if(e=b(t,r.value,!1))break}}catch(t){i.e(t)}finally{i.f()}var u,l=o(c.displayMath);try{for(l.s();!(u=l.n()).done;){if(n=b(t,u.value,!0))break}}catch(t){l.e(t)}finally{l.f()}return e&&(null===n?a.push(e):n.index>e.index&&(a.push(e),n.index<e.endIndex&&(n=null))),n&&a.push(n),a}function O(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",r=e.content.length,o=m(window.btoa(encodeURIComponent(e.content)),"".concat(n));return t=t.substring(0,e.index)+o+t.substring(e.index+r,t.length)}function J(t){for(var e,n=function(){var n=e[0],r=e[1]||"";t=t.replace(n,(function(){return decodeURIComponent(window.atob(r))}))};null!==(e=E.commentCodeReplaceMarkup.exec(t));)n();return t}function j(){return C.apply(this,arguments)}function C(){return(C=n(t().mark((function e(){var n,r,a,i,c;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:p.prepareRender(),n=document.getElementsByTagName(u),r=o(n),t.prev=3,r.s();case 5:if((a=r.n()).done){t.next=12;break}return i=a.value,c="true"===i.getAttribute(f),t.next=10,p.renderElement(i,c);case 10:t.next=5;break;case 12:t.next=17;break;case 14:t.prev=14,t.t0=t.catch(3),r.e(t.t0);case 17:return t.prev=17,r.f(),t.finish(17);case 20:p.afterRender();case 21:case"end":return t.stop()}}),e,null,[[3,14,17,20]])})))).apply(this,arguments)}window&&(window.$docsify.plugins=[].concat(window.$docsify.plugins||[],(function(e,r){e.beforeEach((function(t,e){e(t=function(t){for(var e,n,r;null!==(e=M(t,E.codeTagMarkup));)t=O(t,e,k);for(;null!==(e=M(t,E.codeBlockMarkup));)t=O(t,e,k);for(;null!==(e=M(t,E.codeInlineMarkup));)t=O(t,e,k);for(;0!==(n=L(t)).length;){var a,i=-1,l=0,s=o(n);try{for(s.s();!(a=s.n()).done;){var h=(e=a.value).content.length,d=p.prepareContent(e.content,e.innerContent);d=J(d);var v=[];if(v.push("".concat(f,'="').concat(e.displayMode,'"')),c.overflowScroll){var y=e.displayMode?"block":"inline-flex";v.push('style="max-width: 100%;display: '.concat(y,';overflow: auto hidden;"'))}var x="<".concat(u," ").concat(v.join(" "),">").concat((r=d,r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")),"</").concat(u,">"),w=m(window.btoa(encodeURIComponent(x))),b=e.index;e.index>i&&(b+=l),i=e.index,l=w.length-h,t=t.substring(0,b)+w+t.substring(b+h,t.length)}}catch(t){s.e(t)}finally{s.f()}}return(t=J(t)).replaceAll(E.commentDeleteReplaceMarkup,"$1".concat(g,"\x3c!--"))}(t))})),e.afterEach((function(t,e){e(t=function(t){var e;t=t.replaceAll(g,"");for(var n=function(){var n=e[0],r=e[1]||"";t=t.replace(n,(function(){return decodeURIComponent(window.atob(r))}))};null!==(e=E.commentReplaceMarkup.exec(t));)n();return t}(t))})),e.doneEach(n(t().mark((function e(){return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,j();case 2:case"end":return t.stop()}}),e)}))))})))}(); //# sourceMappingURL=docsify-latex.min.js.map