Added markdown null check and reapply markdown in all cases

parent null check applyMarkdownToNode
This commit is contained in:
sub-hub
2024-05-06 17:10:26 +09:00
parent e204eeb385
commit 9b3571beeb
2 changed files with 7 additions and 10 deletions

View File

@@ -316,6 +316,7 @@ export async function translateHTML(html: string, reverse:boolean, charArg:simpl
let translated = await translate(node.textContent || "", reverse);
if (!reprocessDisplayScript) {
node.textContent = translated;
applyMarkdownToNode(node);
return;
}
@@ -325,12 +326,6 @@ export async function translateHTML(html: string, reverse:boolean, charArg:simpl
"editdisplay",
chatID
);
// If the translation is the same, don't replace the node
if (translated == processedTranslated) {
node.textContent = processedTranslated;
return;
}
// Replace the old node with the new one
const newNode = document.createElement(

View File

@@ -574,10 +574,12 @@ export function applyMarkdownToNode(node: Node) {
span.innerHTML = markdown;
// inherit inline style from the parent node
const parentStyle = (node.parentNode as HTMLElement).style;
for(let i=0;i<parentStyle.length;i++){
span.style.setProperty(parentStyle[i], parentStyle.getPropertyValue(parentStyle[i]))
}
const parentStyle = (node.parentNode as HTMLElement)?.style;
if(parentStyle){
for(let i=0;i<parentStyle.length;i++){
span.style.setProperty(parentStyle[i], parentStyle.getPropertyValue(parentStyle[i]))
}
}
(node as Element)?.replaceWith(span);
return
}