import { parse } from 'node-html-parser';
// Fandom/MediaWiki cruft that adds no value in a reader UI.
const REMOVE_SELECTORS = [
'script',
'.mw-editsection',
'.mw-empty-elt',
// ad rails / sidebars occasionally present in parsed output
'.wds-global-footer',
'.page-side-tools',
'[data-ad]',
'.ad-slot',
// Fandom-injected FAQ/engagement widgets (trfc161 etc.)
'[class^="trfc"]',
// caption info icons reference Fandom's SVG sprite sheet, which we don't serve
'.info-icon'
];
/**
* Sanitize and rewrite a MediaWiki `parse` HTML fragment for our reader UI.
*
* - Internal `/wiki/X` links are rewritten to `//wiki/X`; category links
* `/wiki/Category:X` become `//category/X`. Query/hash preserved.
* - External (http/https) links get `target="_blank"` + safe `rel`.
* - `