mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-21 08:46:50 +02:00
fix: improve katex support
This commit is contained in:
@@ -21,6 +21,7 @@ function defaultTask(cb) {
|
|||||||
"public/script/external/prism.min.js",
|
"public/script/external/prism.min.js",
|
||||||
"public/script/external/katex.min.js",
|
"public/script/external/katex.min.js",
|
||||||
"public/script/external/katex-auto-render.min.js",
|
"public/script/external/katex-auto-render.min.js",
|
||||||
|
"public/script/external/marked-katex-extension.umd.min.js",
|
||||||
"public/script/external/notebook.min.js",
|
"public/script/external/notebook.min.js",
|
||||||
"public/script/external/org.js",
|
"public/script/external/org.js",
|
||||||
"public/script/external/jquery-3.4.1.min.js",
|
"public/script/external/jquery-3.4.1.min.js",
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Minified by jsDelivr using Terser v5.19.2.
|
||||||
|
* Original file: /npm/marked-katex-extension@5.0.1/lib/index.umd.js
|
||||||
|
*
|
||||||
|
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
||||||
|
*/
|
||||||
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).markedKatex=t(e.katex)}(this,(function(e){"use strict";const t=/^(\${1,2})(?!\$)((?:\\.|[^\\\n])*?(?:\\.|[^\\\n\$]))\1(?=[\s?!\.,:?!。,:]|$)/,n=/^(\${1,2})\n((?:\\[^]|[^\\])+?)\n\1(?:\n|$)/;function r(t,n){return r=>e.renderToString(r.text,{...t,displayMode:r.displayMode})+(n?"\n":"")}function i(e,n){return{name:"inlineKatex",level:"inline",start(e){let n,r=e;for(;r;){if(n=r.indexOf("$"),-1===n)return;if(0===n||" "===r.charAt(n-1)){if(r.substring(n).match(t))return n}r=r.substring(n+1).replace(/^\$+/,"")}},tokenizer(e,n){const r=e.match(t);if(r)return{type:"inlineKatex",raw:r[0],text:r[2].trim(),displayMode:2===r[1].length}},renderer:n}}function o(e,t){return{name:"blockKatex",level:"block",tokenizer(e,t){const r=e.match(n);if(r)return{type:"blockKatex",raw:r[0],text:r[2].trim(),displayMode:2===r[1].length}},renderer:t}}return function(e={}){return{extensions:[i(e,r(e,!1)),o(e,r(e,!0))]}}}));
|
||||||
|
//# sourceMappingURL=/sm/25cb250346ed1262c6185eedae00cfd6f44bba21eb2c1bf521e994aa1d145555.map
|
||||||
+5
-43
@@ -153,49 +153,6 @@ function renderMD(md, baseUrlValue) {
|
|||||||
md = contentAbs2Relative(md, baseUrlValue);
|
md = contentAbs2Relative(md, baseUrlValue);
|
||||||
const renderer = new marked.Renderer();
|
const renderer = new marked.Renderer();
|
||||||
|
|
||||||
const replacer = ((blockRegex, inlineRegex) => (text) => {
|
|
||||||
text = text.replace(blockRegex, (match, expression) => {
|
|
||||||
return katex.renderToString(expression, { displayMode: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
text = text.replace(inlineRegex, (match, expression) => {
|
|
||||||
return katex.renderToString(expression, { displayMode: false });
|
|
||||||
});
|
|
||||||
|
|
||||||
return text;
|
|
||||||
})(/\$\$([\s\S]+?)\$\$/g, /\$([^\n\s]+?)\$/g);
|
|
||||||
|
|
||||||
const replaceTypes = ["listitems", "paragraph", "tablecell", "text"];
|
|
||||||
replaceTypes.forEach((type) => {
|
|
||||||
const original = renderer[type];
|
|
||||||
renderer[type] = (...args) => {
|
|
||||||
args[0] = replacer(args[0]);
|
|
||||||
return original(...args);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const rendererCode = renderer.code;
|
|
||||||
renderer.code = function (code, lang, escaped) {
|
|
||||||
if (!lang) {
|
|
||||||
const math = replacer(code);
|
|
||||||
if (math != code) {
|
|
||||||
return math;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// call default renderer
|
|
||||||
return rendererCode.call(this, code, lang, escaped);
|
|
||||||
};
|
|
||||||
|
|
||||||
const rendererCodespan = renderer.codespan;
|
|
||||||
renderer.codespan = function (text) {
|
|
||||||
const math = replacer(text);
|
|
||||||
if (math != text) {
|
|
||||||
return math;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rendererCodespan.call(this, text);
|
|
||||||
};
|
|
||||||
|
|
||||||
const rendererLink = renderer.link;
|
const rendererLink = renderer.link;
|
||||||
renderer.link = function (href, title, text) {
|
renderer.link = function (href, title, text) {
|
||||||
// wrap videos links (mp4 and mov) with media https://github.blog/2021-05-13-video-uploads-available-github/
|
// wrap videos links (mp4 and mov) with media https://github.blog/2021-05-13-video-uploads-available-github/
|
||||||
@@ -220,5 +177,10 @@ function renderMD(md, baseUrlValue) {
|
|||||||
if (baseUrlValue) {
|
if (baseUrlValue) {
|
||||||
marked.use(baseUrl(baseUrlValue));
|
marked.use(baseUrl(baseUrlValue));
|
||||||
}
|
}
|
||||||
|
marked.use(
|
||||||
|
markedKatex({
|
||||||
|
throwOnError: false,
|
||||||
|
})
|
||||||
|
);
|
||||||
return marked.parse(md, { renderer });
|
return marked.parse(md, { renderer });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user