fix: DOMParser guard in translation simplification; translate test contract updated to html mode
All checks were successful
Forgejo Android APK / Root app tests (push) Successful in 51s
Forgejo Android APK / Build signed APK (push) Successful in 1m58s

This commit is contained in:
Daniel 2026-09-09 05:09:02 +02:00
parent 07af95b89a
commit ec4f1905de
2 changed files with 6 additions and 2 deletions

View file

@ -1618,6 +1618,10 @@ import {
}
function simplifyHtmlForTranslation(html) {
if (typeof DOMParser === 'undefined') {
// Older harnesses/browsers: send the raw markdown as text instead.
return String(html || '').replace(/<[^>]*>/g, '');
}
var doc = new DOMParser().parseFromString(String(html || ''), 'text/html');
doc.body.querySelectorAll('.katex, .assistant-cite, .assistant-code-copy, .assistant-table-actions, .assistant-msg-actions, mjx-container, script, style').forEach(function(el) {
el.replaceWith(doc.createTextNode(el.textContent || ''));

View file

@ -177,8 +177,8 @@ test('per-message translate picker offers a provider choice and leaves the raw t
const sent = JSON.parse(translateCalls[0].options.body);
assert.equal(sent.target, 'es');
assert.equal(sent.provider, 'libretranslate');
assert.equal(sent.format, 'text');
assert.equal(sent.message, 'Chest pain in a four year old.');
assert.equal(sent.format, 'html');
assert.match(sent.message, /Chest pain in a four year old\./, 'simplified rendered HTML carries the formatting');
const bubble = row.querySelector('.assistant-bubble');
assert.match(bubble.textContent, /Traducción de "Chest pain in a four year old/);
assert.equal(c.messages[0].content, 'Chest pain in a four year old.', 'canonical transcript unchanged');