| 408 | 408 | |
| 409 | 409 | // split text by embedded images links |
| 410 | 410 | const chunks = text.split(/!\[.*?]\([^)]*\)/); |
| 411 | 411 | const links = [ ...text.matchAll(/!\[.*?]\([^)]*\)/g) ]; |
| 412 | 412 | |
| 413 | 413 | let rresult = ""''; |
| 414 | 414 | for (let i = 0; i < chunks.length; i++) { |
| 415 | 415 | rresult += await translateInner(chunks[i], lang); |
| 416 | 416 | if (i < links.length) rresult += links[i][0]; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | return rresult; |
| 420 | 420 | } catch (error) { |
| 421 | 421 | console.log(error); |
| 422 | 422 | toastr.error(String(error), 'Failed to translate message'); |