Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle legacy named character references correctly
Fixes #67.
- Loading branch information
1 parent
24377e2
commit 903c6b5
Showing
8 changed files
with
157 additions
and
106 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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
'use strict'; | |||
|
|||
const namedReferences = Object.keys( | |||
require('../data/decode-map.json') | |||
).sort((a, b) => b.length - a.length); | |||
|
|||
// const Trie = require('regexgen').Trie; | |||
// const trie = new Trie(); | |||
// trie.addAll(namedReferences); | |||
// const pattern = trie.toString(); | |||
// console.log(pattern); | |||
// → 12 KB instead of the 16 KB of the current output. | |||
// However, the current output gzips better, and has better | |||
// run-time performance. | |||
|
|||
// Verify all references consist of characters that don’t need escaping | |||
// within regular expressions. (If this is not the case, then we can’t | |||
// simply do a `join('|')`.) | |||
console.assert(namedReferences.every((reference) => { | |||
return /^[a-zA-Z0-9]+$/.test(reference); | |||
})); | |||
const regexNamedReference = '&(' + namedReferences.join('|') + ');'; | |||
|
|||
module.exports = regexNamedReference; |
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