fix: remove excess line breaks

This commit is contained in:
Gabe Yuan
2024-02-26 16:34:53 +08:00
parent 420e59bf81
commit 77a37cc6df

View File

@@ -439,6 +439,7 @@ export class Translator {
let q = el.innerText.trim();
this._tranNodes.set(el, q);
const keeps = [];
console.log("q", q);
// 保留元素
const [matchSelector, subSelector] = this._keepSelector;
@@ -462,9 +463,15 @@ export class Translator {
});
if (keeps.length > 0) {
q = text;
// textContent会保留些无用的换行符严重影响翻译质量
if (q.includes("\n")) {
q = text;
} else {
q = text.replaceAll("\n", " ");
}
}
}
console.log("q2", q);
// 太长或太短
if (this._invalidLength(q.replace(/\[(\d+)\]/g, "").trim())) {