From ec4f1905de45b6f88e0663e6a5f3026e18f6e4d5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 9 Sep 2026 05:09:02 +0200 Subject: [PATCH] fix: DOMParser guard in translation simplification; translate test contract updated to html mode --- public/js/clinicalAssistant.js | 4 ++++ test/assistant-translate.test.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/public/js/clinicalAssistant.js b/public/js/clinicalAssistant.js index 98351403..991e05b3 100644 --- a/public/js/clinicalAssistant.js +++ b/public/js/clinicalAssistant.js @@ -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 || '')); diff --git a/test/assistant-translate.test.js b/test/assistant-translate.test.js index 34c2f0bd..7999943a 100644 --- a/test/assistant-translate.test.js +++ b/test/assistant-translate.test.js @@ -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');