handle hasInvalidKatex

This commit is contained in:
lebr0nli 2021-07-24 18:27:44 +08:00
parent 38b6b93388
commit c258ad0777
2 changed files with 27 additions and 18 deletions

View file

@ -70,7 +70,7 @@ function processData(data){
if (column.text) if (column.text)
{ {
var textDiv = document.createElement('div'); var textDiv = document.createElement('div');
textDiv.classList.add('sladerBypassKatexTextArea') textDiv.classList.add('sladerBypassKatexTextArea');
textDiv.textContent = column.text.replaceAll('\n\n\n', '\n\n'); // The replace call is a bit funky but it works. textDiv.textContent = column.text.replaceAll('\n\n\n', '\n\n'); // The replace call is a bit funky but it works.
columnDiv.appendChild(textDiv); columnDiv.appendChild(textDiv);
} }
@ -81,13 +81,16 @@ function processData(data){
image.setAttribute('src', column.images.additional.regular.srcUrl); image.setAttribute('src', column.images.additional.regular.srcUrl);
columnDiv.appendChild(image); columnDiv.appendChild(image);
} }
// Append server-rendered image src url. Used in errorhandling. (See: handleKatexError()) // Append server-rendered image src url. Used in errorhandling. (See: handleKatexError())
if (column.images.latex && column.images.latex.large) if (column.images.latex && column.images.latex.large)
{ {
div.querySelector('.sladerBypassKatex').setAttribute('katexsrc', column.images.latex.large.srcUrl); div.querySelector('.sladerBypassKatex').setAttribute('katexsrc', column.images.latex.large.srcUrl);
} }
// handle hasInvalidKatex
if(column.hasInvalidKatex)
div.querySelector('.sladerBypassKatex').setAttribute('InvalidKatex', "true");
div.querySelector('.sladerBypassKatex').appendChild(columnDiv); div.querySelector('.sladerBypassKatex').appendChild(columnDiv);
}); });
@ -99,6 +102,7 @@ function processData(data){
// Render Katex for each card // Render Katex for each card
expArea.querySelectorAll('.sladerBypassKatex').forEach(textArea => { expArea.querySelectorAll('.sladerBypassKatex').forEach(textArea => {
try { try {
if(!textArea.hasAttribute("InvalidKatex")){
renderMathInElement(textArea, { renderMathInElement(textArea, {
delimiters: [ delimiters: [
{left: "$$", right: "$$", display: true}, {left: "$$", right: "$$", display: true},
@ -114,6 +118,11 @@ function processData(data){
throwOnError : true, throwOnError : true,
errorCallback : function(a, b){ handleKatexError(a, b, textArea); } errorCallback : function(a, b){ handleKatexError(a, b, textArea); }
}); });
}
else{
// sometimes even hasInvalidKatex, textArea still can render without error
handleKatexError("hasInvalidKatex","hasInvalidKatex", textArea);
}
} catch (error) { } catch (error) {
console.error('Katex experienced an error. Attempting to load image replacement.'); console.error('Katex experienced an error. Attempting to load image replacement.');
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "slader bypass", "name": "slader bypass",
"version": "0.7", "version": "0.8",
"author":"Alan Li & Ethan Harvey", "author":"Alan Li & Ethan Harvey",
"description": "Slader/Quizlet 5 solutions limit bypass", "description": "Slader/Quizlet 5 solutions limit bypass",
"permissions": [ "permissions": [