diff --git a/src/public/web-page-translate/google/translate.ts b/src/public/web-page-translate/google/translate.ts index 327f00ab..6dcf307a 100644 --- a/src/public/web-page-translate/google/translate.ts +++ b/src/public/web-page-translate/google/translate.ts @@ -38,8 +38,8 @@ export const translate = async (searchParams: URLSearchParams, totalQText: strin const toResult = (rawResult: string) => { let result: string[] = []; - let preprocessText = rawResult.replace(/.*?<\/i>/g, '').replace(/<[\/]?b>/g, ''); - let matchArray = preprocessText.match(/(?<=.*?(?=<\/a>)/g); + let preprocessText = rawResult.replace(/[\s\S]*?<\/i>/g, '').replace(/<[\/]?b>/g, ''); + let matchArray = preprocessText.match(/(?<=[\s\S]*?(?=<\/a>)/g); if (matchArray) { matchArray.map(v => { const [index, rawResult] = v.split('>'); diff --git a/src/public/web-page-translate/index.ts b/src/public/web-page-translate/index.ts index a9288706..de9e7c24 100644 --- a/src/public/web-page-translate/index.ts +++ b/src/public/web-page-translate/index.ts @@ -22,9 +22,9 @@ let wayOfFontsDisplaying: number = 1; let waitingList: PageTranslateItemEnity[] = []; let updatedList: PageTranslateItemEnity[] = []; -const preIgnoreTagRegExp = /CANVAS|IFRAME|BR|HR|SVG|IMG|SCRIPT|LINK|STYLE|INPUT|TEXTAREA|CODE|#comment/i; -const ignoreTagRegExp = /CANVAS|IFRAME|BR|HR|SVG|IMG|SCRIPT|LINK|STYLE|INPUT|TEXTAREA/i; -const skipTagRegExp = /CODE|#comment/i; +const preIgnoreTagRegExp = /^(CANVAS|IFRAME|BR|HR|SVG|IMG|SCRIPT|LINK|STYLE|INPUT|TEXTAREA|CODE|#comment)$/i; +const ignoreTagRegExp = /^(CANVAS|IFRAME|BR|HR|SVG|IMG|SCRIPT|LINK|STYLE|INPUT|TEXTAREA)$/i; +const skipTagRegExp = /^(CODE|#comment)$/i; let minViewPort = 0; let maxViewPort = 0; diff --git a/src/public/web-page-translate/microsoft/translate.ts b/src/public/web-page-translate/microsoft/translate.ts index 6c05c877..1fb1be3f 100644 --- a/src/public/web-page-translate/microsoft/translate.ts +++ b/src/public/web-page-translate/microsoft/translate.ts @@ -61,7 +61,7 @@ const fetchFromMicrosoft = async (requestArray: { Text: string }[], targetLangua const toResult = (rawResult: string) => { let result: string[] = []; - let matchArray = rawResult.match(/(?<=.*?(?=<\/b[0-9]+>)/g); + let matchArray = rawResult.match(/(?<=[\s\S]*?(?=<\/b[0-9]+>)/g); if (matchArray) { matchArray.map(v => { const [index, rawResult] = v.split('>');