style: apply prettier formatting across codebase

This commit is contained in:
jessy-david-dev
2026-04-11 22:25:34 +02:00
parent b76fbf8789
commit d268905f2d
27 changed files with 2092 additions and 828 deletions
+77 -32
View File
@@ -3,29 +3,59 @@
import { useEffect, useRef } from "react";
const FORBIDDEN_NAMESPACES = [
"Fichier:", "File:", "Wikipedia:", "Aide:", "Help:", "Categorie:", "Category:",
"Discussion:", "Talk:", "Utilisateur:", "User:", "Special:", "Sp\u00e9cial:",
"Portail:", "Portal:", "Mod\u00e8le:", "Template:", "Projet:", "WP:",
"Fichier:",
"File:",
"Wikipedia:",
"Aide:",
"Help:",
"Categorie:",
"Category:",
"Discussion:",
"Talk:",
"Utilisateur:",
"User:",
"Special:",
"Sp\u00e9cial:",
"Portail:",
"Portal:",
"Mod\u00e8le:",
"Template:",
"Projet:",
"WP:",
];
const REMOVED_SECTION_IDS = [
"Liens_externes", "R\u00e9f\u00e9rences", "Notes", "Bibliographie",
"Voir_aussi", "Notes_et_r\u00e9f\u00e9rences", "Sources",
"Annexes", "Articles_connexes",
"Liens_externes",
"R\u00e9f\u00e9rences",
"Notes",
"Bibliographie",
"Voir_aussi",
"Notes_et_r\u00e9f\u00e9rences",
"Sources",
"Annexes",
"Articles_connexes",
];
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"
).forEach((el) => el.remove());
container.querySelectorAll(
".ambox, .tmbox, .cmbox, .ombox, .fmbox, .hatnote, .bandeau-container, .bandeau"
).forEach((el) => el.remove());
container.querySelectorAll(".audio, .audiolink, audio, video").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",
)
.forEach((el) => el.remove());
container
.querySelectorAll(
".ambox, .tmbox, .cmbox, .ombox, .fmbox, .hatnote, .bandeau-container, .bandeau",
)
.forEach((el) => el.remove());
container
.querySelectorAll(".audio, .audiolink, audio, video")
.forEach((el) => el.remove());
container.querySelectorAll(".gallery").forEach((el) => el.remove());
container.querySelectorAll("#toc, .toc").forEach((el) => el.remove());
@@ -68,8 +98,12 @@ export function ArticleView({
const onNavigateRef = useRef(onNavigate);
const disabledRef = useRef(disabled);
useEffect(() => { onNavigateRef.current = onNavigate; });
useEffect(() => { disabledRef.current = disabled; });
useEffect(() => {
onNavigateRef.current = onNavigate;
});
useEffect(() => {
disabledRef.current = disabled;
});
useEffect(() => {
const container = containerRef.current;
@@ -78,21 +112,30 @@ export function ArticleView({
container.innerHTML = html;
cleanWikiHtml(container);
container.querySelectorAll<HTMLAnchorElement>("a[href^='/wiki/']").forEach((link) => {
const href = link.getAttribute("href") ?? "";
const path = href.replace("/wiki/", "");
let decoded: string;
try { decoded = decodeURIComponent(path); } catch { decoded = path; }
const title = decoded.replace(/_/g, " ");
container
.querySelectorAll<HTMLAnchorElement>("a[href^='/wiki/']")
.forEach((link) => {
const href = link.getAttribute("href") ?? "";
const path = href.replace("/wiki/", "");
let decoded: string;
try {
decoded = decodeURIComponent(path);
} catch {
decoded = path;
}
const title = decoded.replace(/_/g, " ");
if (FORBIDDEN_NAMESPACES.some((ns) => title.startsWith(ns)) || title.includes("#")) {
if (
FORBIDDEN_NAMESPACES.some((ns) => title.startsWith(ns)) ||
title.includes("#")
) {
link.removeAttribute("href");
return;
}
link.setAttribute("data-wiki-title", title);
link.removeAttribute("href");
return;
}
link.setAttribute("data-wiki-title", title);
link.removeAttribute("href");
link.classList.add("wiki-link");
});
link.classList.add("wiki-link");
});
container.querySelectorAll<HTMLAnchorElement>("a[href]").forEach((link) => {
link.removeAttribute("href");
@@ -100,7 +143,9 @@ export function ArticleView({
const handleClick = (e: MouseEvent) => {
if (disabledRef.current) return;
const target = (e.target as HTMLElement).closest("[data-wiki-title]") as HTMLElement | null;
const target = (e.target as HTMLElement).closest(
"[data-wiki-title]",
) as HTMLElement | null;
if (!target) return;
e.preventDefault();
const title = target.getAttribute("data-wiki-title");