-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
42 lines (34 loc) · 1.04 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import fs from 'node:fs/promises'
import fetch from 'node-fetch'
import {fromHtml} from 'hast-util-from-html'
import {selectAll} from 'hast-util-select'
import {toString} from 'hast-util-to-string'
/** @type {Record<number, string>} */
const data = {
0: '�'
}
const response = await fetch(
'https://html.spec.whatwg.org/multipage/parsing.html'
)
const text = await response.text()
const tree = fromHtml(text)
const rows = selectAll('#table-charref-overrides tbody tr', tree)
let index = -1
while (++index < rows.length) {
const cells = selectAll('td', rows[index])
const key = Number.parseInt(toString(cells[0]).slice(2), 16)
const value = Number.parseInt(toString(cells[1]).slice(2), 16)
data[key] = String.fromCodePoint(value)
}
await fs.writeFile(
'index.js',
[
'/**',
' * Map of invalid numeric character references to their replacements, according to HTML.',
' *',
' * @type {Record<number, string>} ',
' */',
'export const characterReferenceInvalid = ' + JSON.stringify(data, null, 2),
''
].join('\n')
)