🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
124
node_modules/parse-entities/index.d.ts
generated
vendored
Normal file
124
node_modules/parse-entities/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
import type {Point, Position} from 'unist'
|
||||
|
||||
/**
|
||||
* @typeParam Context
|
||||
* Value used as `this`.
|
||||
* @this
|
||||
* The `warningContext` given to `parseEntities`
|
||||
* @param reason
|
||||
* Human readable reason for emitting a parse error.
|
||||
* @param point
|
||||
* Place where the error occurred.
|
||||
* @param code
|
||||
* Machine readable code the error.
|
||||
*/
|
||||
export type WarningHandler<Context = undefined> = (
|
||||
this: Context,
|
||||
reason: string,
|
||||
point: Point,
|
||||
code: number
|
||||
) => void
|
||||
|
||||
/**
|
||||
* @typeParam Context
|
||||
* Value used as `this`.
|
||||
* @this
|
||||
* The `referenceContext` given to `parseEntities`
|
||||
* @param value
|
||||
* Decoded character reference.
|
||||
* @param position
|
||||
* Place where `value` starts and ends.
|
||||
* @param source
|
||||
* Raw source of character reference.
|
||||
*/
|
||||
export type ReferenceHandler<Context = undefined> = (
|
||||
this: Context,
|
||||
value: string,
|
||||
position: Position,
|
||||
source: string
|
||||
) => void
|
||||
|
||||
/**
|
||||
* @typeParam Context
|
||||
* Value used as `this`.
|
||||
* @this
|
||||
* The `textContext` given to `parseEntities`.
|
||||
* @param value
|
||||
* String of content.
|
||||
* @param position
|
||||
* Place where `value` starts and ends.
|
||||
*/
|
||||
export type TextHandler<Context = undefined> = (
|
||||
this: Context,
|
||||
value: string,
|
||||
position: Position
|
||||
) => void
|
||||
|
||||
/**
|
||||
* Configuration.
|
||||
*
|
||||
* @typeParam WarningContext
|
||||
* Value used as `this` in the `warning` handler.
|
||||
* @typeParam ReferenceContext
|
||||
* Value used as `this` in the `reference` handler.
|
||||
* @typeParam TextContext
|
||||
* Value used as `this` in the `text` handler.
|
||||
*/
|
||||
export type Options<
|
||||
WarningContext = undefined,
|
||||
ReferenceContext = undefined,
|
||||
TextContext = undefined
|
||||
> = {
|
||||
/**
|
||||
* Additional character to accept.
|
||||
* This allows other characters, without error, when following an ampersand.
|
||||
*
|
||||
* @default ''
|
||||
*/
|
||||
additional?: string
|
||||
/**
|
||||
* Whether to parse `value` as an attribute value.
|
||||
* This results in slightly different behavior.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
attribute?: boolean
|
||||
/**
|
||||
* Whether to allow nonterminated character references.
|
||||
* For example, `©cat` for `©cat`.
|
||||
* This behavior is compliant to the spec but can lead to unexpected results.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
nonTerminated?: boolean
|
||||
/**
|
||||
* Starting `position` of `value` (`Point` or `Position`). Useful when dealing with values nested in some sort of syntax tree.
|
||||
*/
|
||||
position?: Position | Point
|
||||
/**
|
||||
* Context used when calling `warning`.
|
||||
*/
|
||||
warningContext?: WarningContext
|
||||
/**
|
||||
* Context used when calling `reference`.
|
||||
*/
|
||||
referenceContext?: ReferenceContext
|
||||
/**
|
||||
* Context used when calling `text`.
|
||||
*/
|
||||
textContext?: TextContext
|
||||
/**
|
||||
* Warning handler.
|
||||
*/
|
||||
warning?: WarningHandler<WarningContext>
|
||||
/**
|
||||
* Reference handler.
|
||||
*/
|
||||
reference?: ReferenceHandler<ReferenceContext>
|
||||
/**
|
||||
* Text handler.
|
||||
*/
|
||||
text?: TextHandler<TextContext>
|
||||
}
|
||||
|
||||
export {parseEntities} from './lib/index.js'
|
||||
3
node_modules/parse-entities/index.js
generated
vendored
Normal file
3
node_modules/parse-entities/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Note: more types exposed from `index.d.ts`.
|
||||
// To do: refactor to include type parameters in JS.
|
||||
export {parseEntities} from './lib/index.js'
|
||||
14
node_modules/parse-entities/lib/index.d.ts
generated
vendored
Normal file
14
node_modules/parse-entities/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* Parse HTML character references.
|
||||
*
|
||||
* @param {string} value
|
||||
* @param {import('../index.js').Options} [options={}]
|
||||
*/
|
||||
export function parseEntities(
|
||||
value: string,
|
||||
options?:
|
||||
| import('../index.js').Options<undefined, undefined, undefined>
|
||||
| undefined
|
||||
): string
|
||||
export type Point = import('unist').Point
|
||||
export type Position = import('unist').Position
|
||||
406
node_modules/parse-entities/lib/index.js
generated
vendored
Normal file
406
node_modules/parse-entities/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,406 @@
|
|||
/**
|
||||
* @typedef {import('unist').Point} Point
|
||||
* @typedef {import('unist').Position} Position
|
||||
*/
|
||||
|
||||
import {characterEntitiesLegacy} from 'character-entities-legacy'
|
||||
import {characterReferenceInvalid} from 'character-reference-invalid'
|
||||
import {isDecimal} from 'is-decimal'
|
||||
import {isHexadecimal} from 'is-hexadecimal'
|
||||
import {isAlphanumerical} from 'is-alphanumerical'
|
||||
import {decodeNamedCharacterReference} from 'decode-named-character-reference'
|
||||
|
||||
const fromCharCode = String.fromCharCode
|
||||
|
||||
// Warning messages.
|
||||
const messages = [
|
||||
'',
|
||||
/* 1: Non terminated (named) */
|
||||
'Named character references must be terminated by a semicolon',
|
||||
/* 2: Non terminated (numeric) */
|
||||
'Numeric character references must be terminated by a semicolon',
|
||||
/* 3: Empty (named) */
|
||||
'Named character references cannot be empty',
|
||||
/* 4: Empty (numeric) */
|
||||
'Numeric character references cannot be empty',
|
||||
/* 5: Unknown (named) */
|
||||
'Named character references must be known',
|
||||
/* 6: Disallowed (numeric) */
|
||||
'Numeric character references cannot be disallowed',
|
||||
/* 7: Prohibited (numeric) */
|
||||
'Numeric character references cannot be outside the permissible Unicode range'
|
||||
]
|
||||
|
||||
/**
|
||||
* Parse HTML character references.
|
||||
*
|
||||
* @param {string} value
|
||||
* @param {import('../index.js').Options} [options={}]
|
||||
*/
|
||||
export function parseEntities(value, options = {}) {
|
||||
const additional =
|
||||
typeof options.additional === 'string'
|
||||
? options.additional.charCodeAt(0)
|
||||
: options.additional
|
||||
/** @type {Array<string>} */
|
||||
const result = []
|
||||
let index = 0
|
||||
let lines = -1
|
||||
let queue = ''
|
||||
/** @type {Point|undefined} */
|
||||
let point
|
||||
/** @type {Array<number>|undefined} */
|
||||
let indent
|
||||
|
||||
if (options.position) {
|
||||
if ('start' in options.position || 'indent' in options.position) {
|
||||
// @ts-expect-error: points don’t have indent.
|
||||
indent = options.position.indent
|
||||
// @ts-expect-error: points don’t have indent.
|
||||
point = options.position.start
|
||||
} else {
|
||||
point = options.position
|
||||
}
|
||||
}
|
||||
|
||||
let line = (point ? point.line : 0) || 1
|
||||
let column = (point ? point.column : 0) || 1
|
||||
|
||||
// Cache the current point.
|
||||
let previous = now()
|
||||
/** @type {number|undefined} */
|
||||
let character
|
||||
|
||||
// Ensure the algorithm walks over the first character (inclusive).
|
||||
index--
|
||||
|
||||
while (++index <= value.length) {
|
||||
// If the previous character was a newline.
|
||||
if (character === 10 /* `\n` */) {
|
||||
column = (indent ? indent[lines] : 0) || 1
|
||||
}
|
||||
|
||||
character = value.charCodeAt(index)
|
||||
|
||||
if (character === 38 /* `&` */) {
|
||||
const following = value.charCodeAt(index + 1)
|
||||
|
||||
// The behavior depends on the identity of the next character.
|
||||
if (
|
||||
following === 9 /* `\t` */ ||
|
||||
following === 10 /* `\n` */ ||
|
||||
following === 12 /* `\f` */ ||
|
||||
following === 32 /* ` ` */ ||
|
||||
following === 38 /* `&` */ ||
|
||||
following === 60 /* `<` */ ||
|
||||
Number.isNaN(following) ||
|
||||
(additional && following === additional)
|
||||
) {
|
||||
// Not a character reference.
|
||||
// No characters are consumed, and nothing is returned.
|
||||
// This is not an error, either.
|
||||
queue += fromCharCode(character)
|
||||
column++
|
||||
continue
|
||||
}
|
||||
|
||||
const start = index + 1
|
||||
let begin = start
|
||||
let end = start
|
||||
/** @type {string} */
|
||||
let type
|
||||
|
||||
if (following === 35 /* `#` */) {
|
||||
// Numerical reference.
|
||||
end = ++begin
|
||||
|
||||
// The behavior further depends on the next character.
|
||||
const following = value.charCodeAt(end)
|
||||
|
||||
if (following === 88 /* `X` */ || following === 120 /* `x` */) {
|
||||
// ASCII hexadecimal digits.
|
||||
type = 'hexadecimal'
|
||||
end = ++begin
|
||||
} else {
|
||||
// ASCII decimal digits.
|
||||
type = 'decimal'
|
||||
}
|
||||
} else {
|
||||
// Named reference.
|
||||
type = 'named'
|
||||
}
|
||||
|
||||
let characterReferenceCharacters = ''
|
||||
let characterReference = ''
|
||||
let characters = ''
|
||||
// Each type of character reference accepts different characters.
|
||||
// This test is used to detect whether a reference has ended (as the semicolon
|
||||
// is not strictly needed).
|
||||
const test =
|
||||
type === 'named'
|
||||
? isAlphanumerical
|
||||
: type === 'decimal'
|
||||
? isDecimal
|
||||
: isHexadecimal
|
||||
|
||||
end--
|
||||
|
||||
while (++end <= value.length) {
|
||||
const following = value.charCodeAt(end)
|
||||
|
||||
if (!test(following)) {
|
||||
break
|
||||
}
|
||||
|
||||
characters += fromCharCode(following)
|
||||
|
||||
// Check if we can match a legacy named reference.
|
||||
// If so, we cache that as the last viable named reference.
|
||||
// This ensures we do not need to walk backwards later.
|
||||
if (type === 'named' && characterEntitiesLegacy.includes(characters)) {
|
||||
characterReferenceCharacters = characters
|
||||
// @ts-expect-error: always able to decode.
|
||||
characterReference = decodeNamedCharacterReference(characters)
|
||||
}
|
||||
}
|
||||
|
||||
let terminated = value.charCodeAt(end) === 59 /* `;` */
|
||||
|
||||
if (terminated) {
|
||||
end++
|
||||
|
||||
const namedReference =
|
||||
type === 'named' ? decodeNamedCharacterReference(characters) : false
|
||||
|
||||
if (namedReference) {
|
||||
characterReferenceCharacters = characters
|
||||
characterReference = namedReference
|
||||
}
|
||||
}
|
||||
|
||||
let diff = 1 + end - start
|
||||
let reference = ''
|
||||
|
||||
if (!terminated && options.nonTerminated === false) {
|
||||
// Empty.
|
||||
} else if (!characters) {
|
||||
// An empty (possible) reference is valid, unless it’s numeric (thus an
|
||||
// ampersand followed by an octothorp).
|
||||
if (type !== 'named') {
|
||||
warning(4 /* Empty (numeric) */, diff)
|
||||
}
|
||||
} else if (type === 'named') {
|
||||
// An ampersand followed by anything unknown, and not terminated, is
|
||||
// invalid.
|
||||
if (terminated && !characterReference) {
|
||||
warning(5 /* Unknown (named) */, 1)
|
||||
} else {
|
||||
// If there’s something after an named reference which is not known,
|
||||
// cap the reference.
|
||||
if (characterReferenceCharacters !== characters) {
|
||||
end = begin + characterReferenceCharacters.length
|
||||
diff = 1 + end - begin
|
||||
terminated = false
|
||||
}
|
||||
|
||||
// If the reference is not terminated, warn.
|
||||
if (!terminated) {
|
||||
const reason = characterReferenceCharacters
|
||||
? 1 /* Non terminated (named) */
|
||||
: 3 /* Empty (named) */
|
||||
|
||||
if (options.attribute) {
|
||||
const following = value.charCodeAt(end)
|
||||
|
||||
if (following === 61 /* `=` */) {
|
||||
warning(reason, diff)
|
||||
characterReference = ''
|
||||
} else if (isAlphanumerical(following)) {
|
||||
characterReference = ''
|
||||
} else {
|
||||
warning(reason, diff)
|
||||
}
|
||||
} else {
|
||||
warning(reason, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reference = characterReference
|
||||
} else {
|
||||
if (!terminated) {
|
||||
// All nonterminated numeric references are not rendered, and emit a
|
||||
// warning.
|
||||
warning(2 /* Non terminated (numeric) */, diff)
|
||||
}
|
||||
|
||||
// When terminated and numerical, parse as either hexadecimal or
|
||||
// decimal.
|
||||
let referenceCode = Number.parseInt(
|
||||
characters,
|
||||
type === 'hexadecimal' ? 16 : 10
|
||||
)
|
||||
|
||||
// Emit a warning when the parsed number is prohibited, and replace with
|
||||
// replacement character.
|
||||
if (prohibited(referenceCode)) {
|
||||
warning(7 /* Prohibited (numeric) */, diff)
|
||||
reference = fromCharCode(65533 /* `<60>` */)
|
||||
} else if (referenceCode in characterReferenceInvalid) {
|
||||
// Emit a warning when the parsed number is disallowed, and replace by
|
||||
// an alternative.
|
||||
warning(6 /* Disallowed (numeric) */, diff)
|
||||
reference = characterReferenceInvalid[referenceCode]
|
||||
} else {
|
||||
// Parse the number.
|
||||
let output = ''
|
||||
|
||||
// Emit a warning when the parsed number should not be used.
|
||||
if (disallowed(referenceCode)) {
|
||||
warning(6 /* Disallowed (numeric) */, diff)
|
||||
}
|
||||
|
||||
// Serialize the number.
|
||||
if (referenceCode > 0xffff) {
|
||||
referenceCode -= 0x10000
|
||||
output += fromCharCode((referenceCode >>> (10 & 0x3ff)) | 0xd800)
|
||||
referenceCode = 0xdc00 | (referenceCode & 0x3ff)
|
||||
}
|
||||
|
||||
reference = output + fromCharCode(referenceCode)
|
||||
}
|
||||
}
|
||||
|
||||
// Found it!
|
||||
// First eat the queued characters as normal text, then eat a reference.
|
||||
if (reference) {
|
||||
flush()
|
||||
|
||||
previous = now()
|
||||
index = end - 1
|
||||
column += end - start + 1
|
||||
result.push(reference)
|
||||
const next = now()
|
||||
next.offset++
|
||||
|
||||
if (options.reference) {
|
||||
options.reference.call(
|
||||
options.referenceContext,
|
||||
reference,
|
||||
{start: previous, end: next},
|
||||
value.slice(start - 1, end)
|
||||
)
|
||||
}
|
||||
|
||||
previous = next
|
||||
} else {
|
||||
// If we could not find a reference, queue the checked characters (as
|
||||
// normal characters), and move the pointer to their end.
|
||||
// This is possible because we can be certain neither newlines nor
|
||||
// ampersands are included.
|
||||
characters = value.slice(start - 1, end)
|
||||
queue += characters
|
||||
column += characters.length
|
||||
index = end - 1
|
||||
}
|
||||
} else {
|
||||
// Handle anything other than an ampersand, including newlines and EOF.
|
||||
if (character === 10 /* `\n` */) {
|
||||
line++
|
||||
lines++
|
||||
column = 0
|
||||
}
|
||||
|
||||
if (Number.isNaN(character)) {
|
||||
flush()
|
||||
} else {
|
||||
queue += fromCharCode(character)
|
||||
column++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the reduced nodes.
|
||||
return result.join('')
|
||||
|
||||
// Get current position.
|
||||
function now() {
|
||||
return {
|
||||
line,
|
||||
column,
|
||||
offset: index + ((point ? point.offset : 0) || 0)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the warning.
|
||||
*
|
||||
* @param {1|2|3|4|5|6|7} code
|
||||
* @param {number} offset
|
||||
*/
|
||||
function warning(code, offset) {
|
||||
/** @type {ReturnType<now>} */
|
||||
let position
|
||||
|
||||
if (options.warning) {
|
||||
position = now()
|
||||
position.column += offset
|
||||
position.offset += offset
|
||||
|
||||
options.warning.call(
|
||||
options.warningContext,
|
||||
messages[code],
|
||||
position,
|
||||
code
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush `queue` (normal text).
|
||||
* Macro invoked before each reference and at the end of `value`.
|
||||
* Does nothing when `queue` is empty.
|
||||
*/
|
||||
function flush() {
|
||||
if (queue) {
|
||||
result.push(queue)
|
||||
|
||||
if (options.text) {
|
||||
options.text.call(options.textContext, queue, {
|
||||
start: previous,
|
||||
end: now()
|
||||
})
|
||||
}
|
||||
|
||||
queue = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if `character` is outside the permissible unicode range.
|
||||
*
|
||||
* @param {number} code
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function prohibited(code) {
|
||||
return (code >= 0xd800 && code <= 0xdfff) || code > 0x10ffff
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if `character` is disallowed.
|
||||
*
|
||||
* @param {number} code
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function disallowed(code) {
|
||||
return (
|
||||
(code >= 0x0001 && code <= 0x0008) ||
|
||||
code === 0x000b ||
|
||||
(code >= 0x000d && code <= 0x001f) ||
|
||||
(code >= 0x007f && code <= 0x009f) ||
|
||||
(code >= 0xfdd0 && code <= 0xfdef) ||
|
||||
(code & 0xffff) === 0xffff ||
|
||||
(code & 0xffff) === 0xfffe
|
||||
)
|
||||
}
|
||||
22
node_modules/parse-entities/license
generated
vendored
Normal file
22
node_modules/parse-entities/license
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(The MIT License)
|
||||
|
||||
Copyright (c) 2015 Titus Wormer <mailto:tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
90
node_modules/parse-entities/package.json
generated
vendored
Normal file
90
node_modules/parse-entities/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
{
|
||||
"name": "parse-entities",
|
||||
"version": "4.0.1",
|
||||
"description": "Parse HTML character references",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"parse",
|
||||
"html",
|
||||
"character",
|
||||
"reference",
|
||||
"entity",
|
||||
"entities"
|
||||
],
|
||||
"repository": "wooorm/parse-entities",
|
||||
"bugs": "https://github.com/wooorm/parse-entities/issues",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"lib/",
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/unist": "^2.0.0",
|
||||
"character-entities": "^2.0.0",
|
||||
"character-entities-legacy": "^3.0.0",
|
||||
"character-reference-invalid": "^2.0.0",
|
||||
"decode-named-character-reference": "^1.0.0",
|
||||
"is-alphanumerical": "^2.0.0",
|
||||
"is-decimal": "^2.0.0",
|
||||
"is-hexadecimal": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.0.0",
|
||||
"c8": "^7.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^11.0.0",
|
||||
"remark-preset-wooorm": "^9.0.0",
|
||||
"type-coverage": "^2.0.0",
|
||||
"typescript": "^4.0.0",
|
||||
"xo": "^0.53.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepack": "npm run build && npm run format",
|
||||
"build": "tsc --build --clean && tsc --build && type-coverage",
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"test-api": "node --conditions development test.js",
|
||||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
|
||||
"test": "npm run build && npm run format && npm run test-coverage"
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"rules": {
|
||||
"complexity": "off",
|
||||
"max-depth": "off",
|
||||
"no-bitwise": "off",
|
||||
"unicorn/numeric-separators-style": "off",
|
||||
"unicorn/prefer-code-point": "off"
|
||||
}
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
},
|
||||
"typeCoverage": {
|
||||
"atLeast": 100,
|
||||
"detail": true,
|
||||
"strict": true,
|
||||
"ignoreCatch": true
|
||||
}
|
||||
}
|
||||
266
node_modules/parse-entities/readme.md
generated
vendored
Normal file
266
node_modules/parse-entities/readme.md
generated
vendored
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
# parse-entities
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
|
||||
Parse HTML character references.
|
||||
|
||||
## Contents
|
||||
|
||||
* [What is this?](#what-is-this)
|
||||
* [When should I use this?](#when-should-i-use-this)
|
||||
* [Install](#install)
|
||||
* [Use](#use)
|
||||
* [API](#api)
|
||||
* [`parseEntities(value[, options])`](#parseentitiesvalue-options)
|
||||
* [Types](#types)
|
||||
* [Compatibility](#compatibility)
|
||||
* [Security](#security)
|
||||
* [Related](#related)
|
||||
* [Contribute](#contribute)
|
||||
* [License](#license)
|
||||
|
||||
## What is this?
|
||||
|
||||
This is a small and powerful decoder of HTML character references (often called
|
||||
entities).
|
||||
|
||||
## When should I use this?
|
||||
|
||||
You can use this for spec-compliant decoding of character references.
|
||||
It’s small and fast enough to do that well.
|
||||
You can also use this when making a linter, because there are different warnings
|
||||
emitted with reasons for why and positional info on where they happened.
|
||||
|
||||
## Install
|
||||
|
||||
This package is [ESM only][esm].
|
||||
In Node.js (version 14.14+, 16.0+), install with [npm][]:
|
||||
|
||||
```sh
|
||||
npm install parse-entities
|
||||
```
|
||||
|
||||
In Deno with [`esm.sh`][esmsh]:
|
||||
|
||||
```js
|
||||
import {parseEntities} from 'https://esm.sh/parse-entities@3'
|
||||
```
|
||||
|
||||
In browsers with [`esm.sh`][esmsh]:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import {parseEntities} from 'https://esm.sh/parse-entities@3?bundle'
|
||||
</script>
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
import {parseEntities} from 'parse-entities'
|
||||
|
||||
console.log(parseEntities('alpha & bravo')))
|
||||
// => alpha & bravo
|
||||
|
||||
console.log(parseEntities('charlie ©cat; delta'))
|
||||
// => charlie ©cat; delta
|
||||
|
||||
console.log(parseEntities('echo © foxtrot ≠ golf 𝌆 hotel'))
|
||||
// => echo © foxtrot ≠ golf 𝌆 hotel
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This package exports the identifier `parseEntities`.
|
||||
There is no default export.
|
||||
|
||||
### `parseEntities(value[, options])`
|
||||
|
||||
Parse HTML character references.
|
||||
|
||||
##### `options`
|
||||
|
||||
Configuration (optional).
|
||||
|
||||
###### `options.additional`
|
||||
|
||||
Additional character to accept (`string?`, default: `''`).
|
||||
This allows other characters, without error, when following an ampersand.
|
||||
|
||||
###### `options.attribute`
|
||||
|
||||
Whether to parse `value` as an attribute value (`boolean?`, default: `false`).
|
||||
This results in slightly different behavior.
|
||||
|
||||
###### `options.nonTerminated`
|
||||
|
||||
Whether to allow nonterminated references (`boolean`, default: `true`).
|
||||
For example, `©cat` for `©cat`.
|
||||
This behavior is compliant to the spec but can lead to unexpected results.
|
||||
|
||||
###### `options.position`
|
||||
|
||||
Starting `position` of `value` (`Position` or `Point`, optional).
|
||||
Useful when dealing with values nested in some sort of syntax tree.
|
||||
The default is:
|
||||
|
||||
```js
|
||||
{line: 1, column: 1, offset: 0}
|
||||
```
|
||||
|
||||
###### `options.warning`
|
||||
|
||||
Error handler ([`Function?`][warning]).
|
||||
|
||||
###### `options.text`
|
||||
|
||||
Text handler ([`Function?`][text]).
|
||||
|
||||
###### `options.reference`
|
||||
|
||||
Reference handler ([`Function?`][reference]).
|
||||
|
||||
###### `options.warningContext`
|
||||
|
||||
Context used when calling `warning` (`'*'`, optional).
|
||||
|
||||
###### `options.textContext`
|
||||
|
||||
Context used when calling `text` (`'*'`, optional).
|
||||
|
||||
###### `options.referenceContext`
|
||||
|
||||
Context used when calling `reference` (`'*'`, optional)
|
||||
|
||||
##### Returns
|
||||
|
||||
`string` — decoded `value`.
|
||||
|
||||
#### `function warning(reason, point, code)`
|
||||
|
||||
Error handler.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `this` (`*`) — refers to `warningContext` when given to `parseEntities`
|
||||
* `reason` (`string`) — human readable reason for emitting a parse error
|
||||
* `point` ([`Point`][point]) — place where the error occurred
|
||||
* `code` (`number`) — machine readable code the error
|
||||
|
||||
The following codes are used:
|
||||
|
||||
| Code | Example | Note |
|
||||
| ---- | ------------------ | --------------------------------------------- |
|
||||
| `1` | `foo & bar` | Missing semicolon (named) |
|
||||
| `2` | `foo { bar` | Missing semicolon (numeric) |
|
||||
| `3` | `Foo &bar baz` | Empty (named) |
|
||||
| `4` | `Foo &#` | Empty (numeric) |
|
||||
| `5` | `Foo &bar; baz` | Unknown (named) |
|
||||
| `6` | `Foo € baz` | [Disallowed reference][invalid] |
|
||||
| `7` | `Foo � baz` | Prohibited: outside permissible unicode range |
|
||||
|
||||
#### `function text(value, position)`
|
||||
|
||||
Text handler.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `this` (`*`) — refers to `textContext` when given to `parseEntities`
|
||||
* `value` (`string`) — string of content
|
||||
* `position` ([`Position`][position]) — place where `value` starts and ends
|
||||
|
||||
#### `function reference(value, position, source)`
|
||||
|
||||
Character reference handler.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `this` (`*`) — refers to `referenceContext` when given to `parseEntities`
|
||||
* `value` (`string`) — decoded character reference
|
||||
* `position` ([`Position`][position]) — place where `source` starts and ends
|
||||
* `source` (`string`) — raw source of character reference
|
||||
|
||||
## Types
|
||||
|
||||
This package is fully typed with [TypeScript][].
|
||||
It exports the additional types `Options`, `WarningHandler`,
|
||||
`ReferenceHandler`, and `TextHandler`.
|
||||
|
||||
## Compatibility
|
||||
|
||||
This package is at least compatible with all maintained versions of Node.js.
|
||||
As of now, that is Node.js 14.14+ and 16.0+.
|
||||
It also works in Deno and modern browsers.
|
||||
|
||||
## Security
|
||||
|
||||
This package is safe: it matches the HTML spec to parse character references.
|
||||
|
||||
## Related
|
||||
|
||||
* [`wooorm/stringify-entities`](https://github.com/wooorm/stringify-entities)
|
||||
— encode HTML character references
|
||||
* [`wooorm/character-entities`](https://github.com/wooorm/character-entities)
|
||||
— info on character references
|
||||
* [`wooorm/character-entities-html4`](https://github.com/wooorm/character-entities-html4)
|
||||
— info on HTML4 character references
|
||||
* [`wooorm/character-entities-legacy`](https://github.com/wooorm/character-entities-legacy)
|
||||
— info on legacy character references
|
||||
* [`wooorm/character-reference-invalid`](https://github.com/wooorm/character-reference-invalid)
|
||||
— info on invalid numeric character references
|
||||
|
||||
## Contribute
|
||||
|
||||
Yes please!
|
||||
See [How to Contribute to Open Source][contribute].
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://github.com/wooorm/parse-entities/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/wooorm/parse-entities/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/parse-entities.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/wooorm/parse-entities
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/parse-entities.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/parse-entities
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/parse-entities.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=parse-entities
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[esmsh]: https://esm.sh
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
||||
|
||||
[typescript]: https://www.typescriptlang.org
|
||||
|
||||
[warning]: #function-warningreason-point-code
|
||||
|
||||
[text]: #function-textvalue-position
|
||||
|
||||
[reference]: #function-referencevalue-position-source
|
||||
|
||||
[invalid]: https://github.com/wooorm/character-reference-invalid
|
||||
|
||||
[point]: https://github.com/syntax-tree/unist#point
|
||||
|
||||
[position]: https://github.com/syntax-tree/unist#position
|
||||
|
||||
[contribute]: https://opensource.guide/how-to-contribute/
|
||||
Loading…
Add table
Add a link
Reference in a new issue