From d5c9796dbbdf99f33e9d58a48e539297c7734704 Mon Sep 17 00:00:00 2001 From: lszoszk Date: Sun, 8 Nov 2026 14:46:36 +0100 Subject: [PATCH] fix(ask): no raw [[fn:N]] markers in the top match The Ask backend sends paragraph text with the corpus footnote markers. The source cards rendered them through the local corpus record, but the top-match box escaped the raw answer string, so markers showed as text. Both now go through _askParaHtml(): the local (or Spanish) record with footnote buttons when loaded, otherwise the backend text with the markers stripped. Copy writes clean text. Test AR1 with a mocked response. Co-Authored-By: Claude Opus 5.5 --- docs/assets/app.js | 32 +++++++++++------ docs/index.html | 6 ++-- tests/ask-render.spec.ts | 75 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 tests/ask-render.spec.ts diff --git a/docs/assets/app.js b/docs/assets/app.js index 58b9891..e0ee332 100644 --- a/docs/assets/app.js +++ b/docs/assets/app.js @@ -15307,12 +15307,7 @@ function _askRenderSourceCards(data, userQuery, opts = {}) { ? `
↳ ${askEscape(s.headerText)}
` : ''; const arts = s.articles?.length ? `
Articles: ${s.articles.map(askEscape).join(', ')}
` : ''; - const esPara = _askEsPara(s); - const localPara = esPara || state.paragraphById?.get(s.paraId); - const rawText = localPara && typeof renderParagraphHtml === 'function' - ? renderParagraphHtml(localPara.text, localPara.footnotes) - : askEscape(s.text || ''); - const text = annotateTreatyText(rawText, s.committee, s.citedArticles); + const text = annotateTreatyText(_askParaHtml(s), s.committee, s.citedArticles); const why = _askRenderWhyMatched(userQuery, s, ret.articleBoost); const actions = _askRenderSourceActions(s); return ` @@ -15346,6 +15341,19 @@ function _askEsPara(s) { const es = state.esById.get(s.paraId); return es ? { text: es.text, footnotes: es.footnotes || [] } : null; } +// The paragraph Ask returned, as shown: the corpus record when it is loaded +// (Spanish in ES mode), so footnote markers become the usual footnote buttons; +// otherwise the backend text with its [[fn:N]] markers removed — the backend +// sends no footnote texts. +function _askDisplayPara(s) { + if (!s) return null; + return _askEsPara(s) || state.paragraphById?.get(s.paraId) || null; +} +function _askParaHtml(s, fallbackText) { + const p = _askDisplayPara(s); + if (p) return renderParagraphHtml(p.text, p.footnotes); + return askEscape(stripFnMarkers(fallbackText ?? s?.text ?? '')); +} function _askRenderSourceActions(s) { const paraId = s.paraId || ''; @@ -15537,14 +15545,16 @@ function renderAskResult(primaryData, counterData) { ${hint ? `
${hint}
` : ''} `; }; - const topEs = _askEsPara(topSource); - const answerText = topEs ? stripFnMarkers(topEs.text) : data.answer; + // The answer is the top source's text (verbatim); render it like the source cards. + const answerHtml = topSource && (!data.answer || stripFnMarkers(data.answer).trim() === stripFnMarkers(topSource.text || '').trim()) + ? _askParaHtml(topSource, data.answer) + : askEscape(stripFnMarkers(data.answer || '')); const answer = data.answer ? `
Top match · verbatim
First-ranked paragraph below. Read all sources for context — General Comments rarely give a single answer.
${buildSourceContext(topSource)} -
${annotateTreatyText(askEscape(answerText), topSource?.committee, topSource?.citedArticles)}
+
${annotateTreatyText(answerHtml, topSource?.committee, topSource?.citedArticles)}
` : ''; @@ -16148,7 +16158,9 @@ function wireAskTab() { const card = actBtn.closest('.ask-source'); if (act === 'copy') { // Paragraph text + short tag for easy paste-into-notes. - const txt = card?.querySelector('.ask-source-text')?.innerText?.trim() || ''; + const shown = _askDisplayPara({ paraId }); + const txt = shown ? stripFnMarkers(shown.text).trim() + : stripFnMarkers(card?.querySelector('.ask-source-text')?.innerText || '').trim(); const tag = card?.querySelector('.ask-citation')?.innerText?.trim() || ''; const meta = card?.querySelector('.ask-source-meta')?.innerText?.trim() || ''; const payload = [txt, tag ? `\n— ${tag} (${meta})` : ''].join('').trim(); diff --git a/docs/index.html b/docs/index.html index 497e35a..c590425 100644 --- a/docs/index.html +++ b/docs/index.html @@ -155,8 +155,8 @@ } - - + +