-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
43 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.DS_Store | ||
*.d.ts | ||
*.log | ||
coverage/ | ||
node_modules/ | ||
*.d.ts | ||
*.log | ||
.DS_Store | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,46 @@ | ||
import fs from 'node:fs' | ||
import https from 'node:https' | ||
import {bail} from 'bail' | ||
import concat from 'concat-stream' | ||
import concatStream from 'concat-stream' | ||
|
||
https.get('https://www.w3.org/TR/html4/sgml/entities.html', onconnection) | ||
|
||
function onconnection(response) { | ||
response.pipe(concat(onconcat)).on('error', bail) | ||
} | ||
https.get('https://www.w3.org/TR/html4/sgml/entities.html', (response) => { | ||
response.pipe(concatStream(onconcat)).on('error', bail) | ||
}) | ||
|
||
/** | ||
* @param {Buffer} data | ||
*/ | ||
function onconcat(data) { | ||
const value = String(data) | ||
/** @type {Record.<string, string>} */ | ||
const entities = {} | ||
const re = /<!ENTITY([\s\S]+?)-->/g | ||
let match = re.exec(data) | ||
let list | ||
let match = re.exec(value) | ||
|
||
while (match) { | ||
list = match[1].split('--', 1)[0].split(/\s+/).filter(Boolean) | ||
const list = match[1].split('--', 1)[0].split(/\s+/).filter(Boolean) | ||
|
||
if (list[1] === 'CDATA') { | ||
entities[list[0]] = String.fromCharCode( | ||
Number(list[2].split('#')[1].split(';')[0]) | ||
) | ||
} | ||
|
||
match = re.exec(data) | ||
match = re.exec(value) | ||
} | ||
|
||
fs.writeFile( | ||
'index.js', | ||
'export const characterEntitiesHtml4 = ' + | ||
JSON.stringify(entities, null, 2) + | ||
'\n', | ||
[ | ||
'/**', | ||
' * Map of named character references from HTML 4.', | ||
' *', | ||
' * @type {Record<string, string>}', | ||
' */', | ||
'export const characterEntitiesHtml4 = ' + | ||
JSON.stringify(entities, null, 2), | ||
'' | ||
].join('\n'), | ||
bail | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters