Added markdown null check and reapply markdown in all cases
parent null check applyMarkdownToNode
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user