From 12031b750747e881582e94fd234eba2e1df87185 Mon Sep 17 00:00:00 2001 From: jessy-david-dev Date: Mon, 13 Apr 2026 00:01:33 +0200 Subject: [PATCH] fix(article): keep references and related sections visible in wikipedia display --- app/components/ArticleView.tsx | 40 +++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/app/components/ArticleView.tsx b/app/components/ArticleView.tsx index c205c0f..17c8456 100644 --- a/app/components/ArticleView.tsx +++ b/app/components/ArticleView.tsx @@ -26,23 +26,20 @@ const FORBIDDEN_NAMESPACES = [ const REMOVED_SECTION_IDS = [ "Liens_externes", - "R\u00e9f\u00e9rences", - "Notes", - "Bibliographie", - "Voir_aussi", - "Notes_et_r\u00e9f\u00e9rences", - "Sources", - "Annexes", - "Articles_connexes", ]; +function getHeadingId(el: Element): string { + // Nouvelle structure Wikipedia :

+ const idEl = el.querySelector("[id]"); + if (idEl) return idEl.getAttribute("id") ?? ""; + // Ancienne structure :

+ const span = el.querySelector("span[id]"); + return span?.getAttribute("id") ?? ""; +} + function cleanWikiHtml(container: HTMLElement): void { container.querySelectorAll(".mw-editsection").forEach((el) => el.remove()); - container - .querySelectorAll( - ".reflist, .references, .mw-references-wrap, sup.reference, .mw-ref, .reference", - ) - .forEach((el) => el.remove()); + container .querySelectorAll( ".navbox, .navbox-inner, .vertical-navbox, .catlinks, .sistersitebox, .bandeau-portail", @@ -59,6 +56,8 @@ function cleanWikiHtml(container: HTMLElement): void { container.querySelectorAll(".gallery").forEach((el) => el.remove()); container.querySelectorAll("#toc, .toc").forEach((el) => el.remove()); + // Supprimer les divs de navigation pure (liens internes type sommaire flottant) + // mais pas les listes de références qui contiennent des ancres #cite_note- container.querySelectorAll("div, nav").forEach((el) => { const links = el.querySelectorAll("a"); if (links.length > 3) { @@ -66,14 +65,19 @@ function cleanWikiHtml(container: HTMLElement): void { const href = a.getAttribute("href") ?? ""; return href.startsWith("#") || href.includes("#"); }); - if (anchorOnly) el.remove(); + const hasCiteLinks = Array.from(links).some((a) => + (a.getAttribute("href") ?? "").includes("cite_"), + ); + if (anchorOnly && !hasCiteLinks) el.remove(); } }); - container.querySelectorAll("h2, h3").forEach((heading) => { - const span = heading.querySelector("span[id]"); - if (!span) return; - const id = span.getAttribute("id") ?? ""; + // Supprimer les sections indésirables — supporte ancienne et nouvelle structure Wikipedia + // Nouvelle :
/ Ancienne :

+ const headingSelectors = "h2, h3, .mw-heading"; + container.querySelectorAll(headingSelectors).forEach((heading) => { + const id = getHeadingId(heading); + if (!id) return; if (REMOVED_SECTION_IDS.some((s) => id === s || id.startsWith(s + "_"))) { let sibling: Element | null = heading; while (sibling) {