Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions docs/assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15307,12 +15307,7 @@ function _askRenderSourceCards(data, userQuery, opts = {}) {
? `<div class="ask-source-header">↳ ${askEscape(s.headerText)}</div>` : '';
const arts = s.articles?.length
? `<div class="ask-source-articles">Articles: ${s.articles.map(askEscape).join(', ')}</div>` : '';
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 `
Expand Down Expand Up @@ -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 || '';
Expand Down Expand Up @@ -15537,14 +15545,16 @@ function renderAskResult(primaryData, counterData) {
${hint ? `<div class="ask-answer-source-hint">${hint}</div>` : ''}
</div>`;
};
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
? `<div class="ask-answer">
<div class="ask-answer-title">Top match · verbatim</div>
<div class="ask-answer-hint">First-ranked paragraph below. Read all sources for context — General Comments rarely give a single answer.</div>
${buildSourceContext(topSource)}
<div class="ask-answer-body">${annotateTreatyText(askEscape(answerText), topSource?.committee, topSource?.citedArticles)}</div>
<div class="ask-answer-body">${annotateTreatyText(answerHtml, topSource?.committee, topSource?.citedArticles)}</div>
</div>`
: '';

Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@
}
</script>

<link rel="stylesheet" href="assets/tokens.css?v=20261108-8c652d8" />
<link rel="stylesheet" href="assets/app.css?v=20261108-8c652d8" />
<link rel="stylesheet" href="assets/tokens.css?v=20261108-b8aa64d" />
<link rel="stylesheet" href="assets/app.css?v=20261108-b8aa64d" />

<!-- Google Analytics 4 is loaded LAZILY, only after the visitor opts in
via the consent banner — see initConsent()/loadAnalytics() in app.js.
Expand Down Expand Up @@ -1783,7 +1783,7 @@ <h3 id="report-modal-title" class="report-modal-title">What did you spot?</h3>
<div class="diff-tray" id="diff-tray" hidden></div>
<div class="diff-modal" id="diff-modal" hidden></div>

<script type="module" src="assets/app.js?v=20261108-8c652d8"></script>
<script type="module" src="assets/app.js?v=20261108-b8aa64d"></script>
<script src="assets/who.js?v=20261013" data-tool="unhrdb" data-endpoint="https://lszoszk.goatcounter.com/count" defer></script>
<script src="assets/service-notice.js?v=20261022" charset="utf-8" data-app="UNHRDB"
data-effect="Until access is restored, the parts of this site that depend on the server, such as search, are unavailable."
Expand Down
75 changes: 75 additions & 0 deletions tests/ask-render.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { expect, test } from '@playwright/test';
import { bootApp, resetWorkspace } from './_helpers';

/**
* Ask result rendering (mocked backend on the CSP-allowed local-dev origin).
*
* AR1. footnoteMarkers — the backend sends paragraph text with [[fn:N]] markers: the top
* match and the source cards show footnote buttons (paragraph in the local corpus) or
* nothing (paragraph not loaded), never the raw markers; Copy writes clean text.
*/

test.beforeEach(async ({ page }) => {
await resetWorkspace(page);
});

test('AR1. footnoteMarkers · no raw [[fn:N]] in the answer or the sources', async ({ page, context }) => {
try { await context.grantPermissions(['clipboard-read', 'clipboard-write']); } catch { /* WebKit */ }
const cors = { 'access-control-allow-origin': '*', 'content-type': 'application/json' };
await page.route('http://127.0.0.1:8767/**', (route) => {
const path = new URL(route.request().url()).pathname;
return route.fulfill({ status: 200, headers: cors, body: path.endsWith('/api/ask') ? JSON.stringify(ASK_FIXTURE) : '{"ok":true}' });
});
await bootApp(page, '/index.html?ask=' + encodeURIComponent('http://127.0.0.1:8767') + '#ask');
await page.locator('#ask-q').fill('notification requirements for peaceful assembly');
await page.locator('#ask-go').click();
const answer = page.locator('.ask-answer-body');
await expect(answer).toContainText('Having to apply for permission', { timeout: 20_000 });
await expect(answer).not.toContainText('[[fn:');
await expect(page.locator('.ask-source-text').first()).not.toContainText('[[fn:');
await expect(page.locator('.ask-source-text').nth(1)).toContainText('with a marker. And more text');
await expect(page.locator('.ask-source-text').nth(1)).not.toContainText('[[fn:');
// ¶70 is in the local corpus: its markers are footnote buttons, as in the reader.
expect(await answer.locator('[data-fn], .fn-mark, button').count()).toBeGreaterThan(0);
await page.locator('.ask-source').first().locator('[data-act="copy"]').click();
const copied = await page.evaluate(() => navigator.clipboard.readText()).catch(() => null);
if (copied !== null) expect(copied).not.toContain('[[fn:');
});

// /api/ask response (recorded 2026-11-08); the second source is synthetic: a paragraph the
// local corpus does not hold.
const ASK_FIXTURE = {
"query": "notification requirements for peaceful assembly",
"answer": "70. Having to apply for permission from the authorities undercuts the idea that peaceful assembly is a basic right.[[fn:92]] Notification systems requiring that those who intend to organize a peaceful assembly must inform the authorities in advance and provide certain salient details are permissible to the extent necessary to assist the authorities in facilitating the smooth conduct of peaceful assemblies and protecting the rights of others.[[fn:93]] At the same time, this requirement must not be misused to stifle peaceful assemblies and, as in the case of other interferences with the right, must be justifiable on the grounds listed in article 21.[[fn:94]] The enforcement of notification requirements must not become an end in itself.[[fn:95]] Notification procedures should be transparent, not unduly bureaucratic,[[fn:96]] their demands on organizers must be proportionate to the potential public impact of the assembly concerned, and they should be free of charge.",
"retrieval": {},
"sources": [
{
"paraId": "ccpr-c-gc-37-0070",
"docId": "ccpr-c-gc-37",
"signature": "CCPR/C/GC/37",
"committee": "CCPR",
"year": 2020,
"title": "GC37: the right of peaceful assembly (article 21)",
"status": null,
"text": "70. Having to apply for permission from the authorities undercuts the idea that peaceful assembly is a basic right.[[fn:92]] Notification systems requiring that those who intend to organize a peaceful assembly must inform the authorities in advance and provide certain salient details are permissible to the extent necessary to assist the authorities in facilitating the smooth conduct of peaceful assemblies and protecting the rights of others.[[fn:93]] At the same time, this requirement must not be misused to stifle peaceful assemblies and, as in the case of other interferences with the right, must be justifiable on the grounds listed in article 21.[[fn:94]] The enforcement of notification requirements must not become an end in itself.[[fn:95]] Notification procedures should be transparent, not unduly bureaucratic,[[fn:96]] their demands on organizers must be proportionate to the potential public impact of the assembly concerned, and they should be free of charge.",
"match": {
"bandLabel": "excellent",
"score100": 91
}
},
{
"paraId": "ccpr-c-gc-37-9999",
"docId": "ccpr-c-gc-37",
"signature": "CCPR/C/GC/37",
"committee": "CCPR",
"year": 2020,
"title": "GC37: the right of peaceful assembly (article 21)",
"status": null,
"text": "999. A paragraph the local corpus does not hold, with a marker.[[fn:7]] And more text.",
"match": {
"bandLabel": "excellent",
"score100": 91
}
}
]
};
Loading