import { readFileSync } from 'node:fs'; const raw = readFileSync(process.argv[2], 'utf8'); let t = raw .replace(//gi, ' ') .replace(//gi, ' ') .replace(//gi, ' ') .replace(//g, ' ') .replace(/<[^>]+>/g, ' '); const ents = { amp:'&', lt:'<', gt:'>', quot:'"', apos:"'", nbsp:' ', ndash:'–', mdash:'—', rsquo:'’', lsquo:'‘', ldquo:'“', rdquo:'”' }; t = t.replace(/&([a-zA-Z]+);/g, (m,n)=> n in ents ? ents[n] : m) .replace(/&#(\d+);/g, (_m,d)=> String.fromCodePoint(+d)) .replace(/&#x([0-9a-f]+);/gi, (_m,h)=> String.fromCodePoint(parseInt(h,16))); t = t.replace(/[ \t ]+/g,' ').replace(/\s*\n\s*/g,'\n').replace(/\n{2,}/g,'\n').trim(); process.stdout.write(t);