fix: DOMParser guard in translation simplification; translate test contract updated to html mode
This commit is contained in:
parent
07af95b89a
commit
ec4f1905de
2 changed files with 6 additions and 2 deletions
|
|
@ -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 || ''));
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue