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);
|
let translated = await translate(node.textContent || "", reverse);
|
||||||
if (!reprocessDisplayScript) {
|
if (!reprocessDisplayScript) {
|
||||||
node.textContent = translated;
|
node.textContent = translated;
|
||||||
|
applyMarkdownToNode(node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,12 +326,6 @@ export async function translateHTML(html: string, reverse:boolean, charArg:simpl
|
|||||||
"editdisplay",
|
"editdisplay",
|
||||||
chatID
|
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
|
// Replace the old node with the new one
|
||||||
const newNode = document.createElement(
|
const newNode = document.createElement(
|
||||||
|
|||||||
@@ -574,10 +574,12 @@ export function applyMarkdownToNode(node: Node) {
|
|||||||
span.innerHTML = markdown;
|
span.innerHTML = markdown;
|
||||||
|
|
||||||
// inherit inline style from the parent node
|
// inherit inline style from the parent node
|
||||||
const parentStyle = (node.parentNode as HTMLElement).style;
|
const parentStyle = (node.parentNode as HTMLElement)?.style;
|
||||||
for(let i=0;i<parentStyle.length;i++){
|
if(parentStyle){
|
||||||
span.style.setProperty(parentStyle[i], parentStyle.getPropertyValue(parentStyle[i]))
|
for(let i=0;i<parentStyle.length;i++){
|
||||||
}
|
span.style.setProperty(parentStyle[i], parentStyle.getPropertyValue(parentStyle[i]))
|
||||||
|
}
|
||||||
|
}
|
||||||
(node as Element)?.replaceWith(span);
|
(node as Element)?.replaceWith(span);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user