This commit is contained in:
5
node_modules/stringify-entities/lib/util/format-basic.js
generated
vendored
Normal file
5
node_modules/stringify-entities/lib/util/format-basic.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
module.exports = formatBasic
|
||||
|
||||
function formatBasic(code) {
|
||||
return '&#x' + code.toString(16).toUpperCase() + ';'
|
||||
}
|
||||
48
node_modules/stringify-entities/lib/util/format-smart.js
generated
vendored
Normal file
48
node_modules/stringify-entities/lib/util/format-smart.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
module.exports = formatPretty
|
||||
|
||||
var toHexadecimal = require('./to-hexadecimal')
|
||||
var toDecimal = require('./to-decimal')
|
||||
var toNamed = require('./to-named')
|
||||
|
||||
// Encode `character` according to `options`.
|
||||
function formatPretty(code, next, options) {
|
||||
var named
|
||||
var numeric
|
||||
var decimal
|
||||
|
||||
if (options.useNamedReferences || options.useShortestReferences) {
|
||||
named = toNamed(
|
||||
code,
|
||||
next,
|
||||
options.omitOptionalSemicolons,
|
||||
options.attribute
|
||||
)
|
||||
}
|
||||
|
||||
if (options.useShortestReferences || !named) {
|
||||
numeric = toHexadecimal(code, next, options.omitOptionalSemicolons)
|
||||
|
||||
// Use the shortest numeric reference when requested.
|
||||
// A simple algorithm would use decimal for all code points under 100, as
|
||||
// those are shorter than hexadecimal:
|
||||
//
|
||||
// * `c` vs `c` (decimal shorter)
|
||||
// * `d` vs `d` (equal)
|
||||
//
|
||||
// However, because we take `next` into consideration when `omit` is used,
|
||||
// And it would be possible that decimals are shorter on bigger values as
|
||||
// well if `next` is hexadecimal but not decimal, we instead compare both.
|
||||
if (options.useShortestReferences) {
|
||||
decimal = toDecimal(code, next, options.omitOptionalSemicolons)
|
||||
|
||||
if (decimal.length < numeric.length) {
|
||||
numeric = decimal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return named &&
|
||||
(!options.useShortestReferences || named.length < numeric.length)
|
||||
? named
|
||||
: numeric
|
||||
}
|
||||
9
node_modules/stringify-entities/lib/util/to-decimal.js
generated
vendored
Normal file
9
node_modules/stringify-entities/lib/util/to-decimal.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = toDecimalReference
|
||||
|
||||
var fromCharCode = require('../constant/from-char-code')
|
||||
|
||||
// Transform `code` into a decimal character reference.
|
||||
function toDecimalReference(code, next, omit) {
|
||||
var value = '&#' + String(code)
|
||||
return omit && next && !/\d/.test(fromCharCode(next)) ? value : value + ';'
|
||||
}
|
||||
11
node_modules/stringify-entities/lib/util/to-hexadecimal.js
generated
vendored
Normal file
11
node_modules/stringify-entities/lib/util/to-hexadecimal.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
module.exports = toHexReference
|
||||
|
||||
var fromCharCode = require('../constant/from-char-code')
|
||||
|
||||
// Transform `code` into a hexadecimal character reference.
|
||||
function toHexReference(code, next, omit) {
|
||||
var value = '&#x' + code.toString(16).toUpperCase()
|
||||
return omit && next && !/[\dA-Fa-f]/.test(fromCharCode(next))
|
||||
? value
|
||||
: value + ';'
|
||||
}
|
||||
33
node_modules/stringify-entities/lib/util/to-named.js
generated
vendored
Normal file
33
node_modules/stringify-entities/lib/util/to-named.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
module.exports = toNamed
|
||||
|
||||
var legacy = require('character-entities-legacy')
|
||||
var characters = require('../constant/characters')
|
||||
var fromCharCode = require('../constant/from-char-code')
|
||||
var own = require('../constant/has-own-property')
|
||||
var dangerous = require('../constant/dangerous.json')
|
||||
|
||||
// Transform `code` into a named character reference.
|
||||
function toNamed(code, next, omit, attribute) {
|
||||
var character = fromCharCode(code)
|
||||
var name
|
||||
var value
|
||||
|
||||
if (own.call(characters, character)) {
|
||||
name = characters[character]
|
||||
value = '&' + name
|
||||
|
||||
if (
|
||||
omit &&
|
||||
own.call(legacy, name) &&
|
||||
dangerous.indexOf(name) === -1 &&
|
||||
(!attribute ||
|
||||
(next && next !== 61 /* `=` */ && /[^\da-z]/i.test(fromCharCode(next))))
|
||||
) {
|
||||
return value
|
||||
}
|
||||
|
||||
return value + ';'
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
Reference in New Issue
Block a user