translation: skip translating pre, code and math tags, closes #1693 (#1698)

This commit is contained in:
Huang Xin
2025-07-28 15:18:19 +08:00
committed by GitHub
parent 23fa2dc8b2
commit b9add62ba7
3 changed files with 11 additions and 7 deletions
+6 -2
View File
@@ -1,4 +1,4 @@
export const walkTextNodes = (root: HTMLElement): HTMLElement[] => {
export const walkTextNodes = (root: HTMLElement, rejectTags: string[] = []): HTMLElement[] => {
const elements: HTMLElement[] = [];
const walk = (node: HTMLElement | Document | ShadowRoot, depth = 0) => {
if (depth > 15) return;
@@ -7,7 +7,11 @@ export const walkTextNodes = (root: HTMLElement): HTMLElement[] => {
}
const children = 'children' in node ? (Array.from(node.children) as HTMLElement[]) : [];
for (const child of children) {
if (child.tagName === 'STYLE' || child.tagName === 'LINK') {
if (
child.tagName === 'STYLE' ||
child.tagName === 'LINK' ||
rejectTags.includes(child.tagName.toLowerCase())
) {
continue;
}
if (child.shadowRoot) {