Skip to content

Commit d6e33e7

Browse files
author
Zhicheng WANG
committed
fix: 对照翻译功能在图片前面的段落上会出错
1 parent be392f1 commit d6e33e7

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • src/app/shared/markdown-viewer/translator

src/app/shared/markdown-viewer/translator/html.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ export namespace html {
6060
export function markAndSwap(root: Element, selector: string): void {
6161
const elements = root.querySelectorAll<HTMLElement>(selector);
6262
elements.forEach(element => {
63-
if (containsChinese(element.innerHTML)) {
63+
if (element.textContent && containsChinese(element.textContent)) {
6464
const prev = element.previousElementSibling;
65-
if (isPaired(prev, element) && !containsChinese(prev.innerHTML)) {
65+
if (prev.textContent && isPaired(prev, element) && !containsChinese(prev.textContent)) {
6666
element.setAttribute('translation-result', 'on');
6767
prev.setAttribute('translation-origin', 'off');
6868
element.parentElement.insertBefore(element, prev);
@@ -118,7 +118,7 @@ export namespace html {
118118
for (let i = 0; i < rows.length - 1; ++i) {
119119
const thisRow = rows.item(i) as HTMLTableRowElement;
120120
const nextRow = rows.item(i + 1) as HTMLTableRowElement;
121-
if (shouldMergeRow(nextRow) && containsChinese(nextRow.innerHTML) && !containsChinese(thisRow.innerHTML)) {
121+
if (shouldMergeRow(nextRow) && containsChinese(nextRow.textContent) && !containsChinese(thisRow.textContent)) {
122122
translationRows.push(nextRow);
123123
mergeRows(thisRow, nextRow);
124124
}

0 commit comments

Comments
 (0)