mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-17 16:29:42 -04:00
Fix catastrophic backtracking
Former-commit-id: b6d4ec6664991164989bc4a809cf13c945adb006 [formerly add1f091841cf936e5e5a02ee7e8d99e9d0b6c57 [formerly 2f34f011c2b41a5501dcb6cfc8e3710ba1d21d80]] Former-commit-id: 28999c62eedfd9966726e4f34b97716e392cf32d Former-commit-id: b3202981b0ee58f9dc6b35252849e0d4fdb87c54
This commit is contained in:
parent
36165215d9
commit
ae05938785
@ -3078,23 +3078,25 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'cook
|
|||||||
/[^\\](\$\$?)((?:\\\$|(?!\1)[\s\S])+)\1/.test(htmlArticle) : false;
|
/[^\\](\$\$?)((?:\\\$|(?!\1)[\s\S])+)\1/.test(htmlArticle) : false;
|
||||||
//Replace all TeX SVGs with MathJax scripts
|
//Replace all TeX SVGs with MathJax scripts
|
||||||
if (params.useMathJax) {
|
if (params.useMathJax) {
|
||||||
htmlArticle = htmlArticle.replace(/<img\s+(?=[^>]+?math-fallback-image)[^>]*?alt\s*=\s*(['"])((?:[^"']|(?!\1)[\s\S])+)[^>]+>/ig,
|
|
||||||
function (p0, p1, math) {
|
|
||||||
// Remove any rogue ampersands in MathJax due to double escaping (by Wikipedia)
|
|
||||||
math = math.replace(/&/g, '&');
|
|
||||||
// Change any mbox commands to fbox (because KaTeX doesn't support mbox)
|
|
||||||
math = math.replace(/mbox{/g, 'fbox{');
|
|
||||||
return '<script type="math/tex">' + math + '</script>';
|
|
||||||
});
|
|
||||||
// Deal with any newer MathML blocks
|
// Deal with any newer MathML blocks
|
||||||
htmlArticle = htmlArticle.replace(/(<math\b[^>]+alttext=(["']))((?:[^"']|[\s\S](?!\2))+?)(\2(?:[^<]|<(?!\/math))+(?:[^<]|<(?!img))+)<img\b[^>]+?class=["'][^"']*?mwe-math-fallback-image[^>]+>/ig,
|
htmlArticle = htmlArticle.replace(/(<math\b[^>]+alttext=(["']))((?:[^"']|[\s\S](?!\2))+?)(\2(?:[^<]|<(?!\/math))+(?:[^<]|<(?!img))+)<img\b[^>]+?class=["'][^"']*?mwe-math-fallback-image[^>]+>/ig,
|
||||||
function (_p0, p1, _p2, math, p4) {
|
function (_p0, p1, _p2, math, p4) {
|
||||||
// Remove any rogue ampersands in MathJax due to double escaping (by Wikipedia)
|
// Remove any rogue ampersands in MathJax due to double escaping (by Wikipedia)
|
||||||
math = math.replace(/&/g, '&');
|
math = math.replace(/&/g, '&');
|
||||||
// Change any mbox commands to fbox (because KaTeX doesn't support mbox)
|
// Change any mbox commands to fbox (because KaTeX doesn't support mbox)
|
||||||
math = math.replace(/mbox{/g, 'fbox{');
|
math = math.replace(/mbox{/g, 'fbox{');
|
||||||
return p1 + math + p4 + '<script type="math/tex">' + math + '</script>';
|
return p1 + math + p4 + '<script type="math/tex">' + math + '</script>';
|
||||||
});
|
});
|
||||||
|
// Older math blocks
|
||||||
|
htmlArticle = htmlArticle.replace(/<img\s+(?=[^>]+?math-fallback-image)[^>]*?alt\s*=\s*(['"])((?:[^"']|(?!\1)[\s\S])+)[^>]+>/ig,
|
||||||
|
function (p0, p1, math) {
|
||||||
|
// Remove any rogue ampersands in MathJax due to double escaping (by Wikipedia)
|
||||||
|
math = math.replace(/&/g, '&');
|
||||||
|
// Change any mbox commands to fbox (because KaTeX doesn't support mbox)
|
||||||
|
math = math.replace(/mbox{/g, 'fbox{');
|
||||||
|
return '<script type="math/tex">' + math + '</script>';
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
params.containsMathTex = params.useMathJax ? /<script\s+type\s*=\s*['"]\s*math\/tex\s*['"]/i.test(htmlArticle) : false;
|
params.containsMathTex = params.useMathJax ? /<script\s+type\s*=\s*['"]\s*math\/tex\s*['"]/i.test(htmlArticle) : false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user