planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

448
node_modules/hast-util-to-text/index.js generated vendored Normal file
View File

@@ -0,0 +1,448 @@
'use strict'
var repeat = require('repeat-string')
var convert = require('hast-util-is-element/convert')
var findAfter = require('unist-util-find-after')
module.exports = toText
var searchLineFeeds = /\n/g
var searchTabOrSpaces = /[\t ]+/g
var br = convert('br')
var p = convert('p')
var cell = convert(['th', 'td'])
var row = convert('tr')
// Note that we dont need to include void elements here as they dont have text.
// See: <https://github.com/wooorm/html-void-elements>
var notRendered = convert([
// List from: <https://html.spec.whatwg.org/#hidden-elements>
'datalist',
'head',
'noembed',
'noframes',
'rp',
'script',
'style',
'template',
'title',
// Act as if we support scripting.
'noscript',
// Hidden attribute.
hidden,
// From: <https://html.spec.whatwg.org/#flow-content-3>
closedDialog
])
// See: <https://html.spec.whatwg.org/#the-css-user-agent-style-sheet-and-presentational-hints>
var blockOrCaption = convert([
'caption', // `table-caption`
// Page
'html',
'body',
// Flow content
'address',
'blockquote',
'center', // Legacy
'dialog',
'div',
'figure',
'figcaption',
'footer',
'form,',
'header',
'hr',
'legend',
'listing', // Legacy
'main',
'p',
'plaintext', // Legacy
'pre',
'xmp', // Legacy
// Sections and headings
'article',
'aside',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'hgroup',
'nav',
'section',
// Lists
'dir', // Legacy
'dd',
'dl',
'dt',
'menu',
'ol',
'ul'
])
// Implementation of the `innerText` getter:
// <https://html.spec.whatwg.org/#the-innertext-idl-attribute>
// Note that we act as if `node` is being rendered, and as if were a
// CSS-supporting user agent.
function toText(node) {
var children = node.children || []
var block = blockOrCaption(node)
var whiteSpace = inferWhiteSpace(node, {})
var index = -1
var results
var result
var value
var count
// Treat `text` and `comment` as having normal white-space.
// This deviates from the spec as in the DOM the nodes `.data` has to be
// returned.
// If you want that behavior use `hast-util-to-string`.
// All other nodes are later handled as if they are `element`s (so the
// algorithm also works on a `root`).
// Nodes without children are treated as a void element, so `doctype` is thus
// ignored.
if (node.type === 'text' || node.type === 'comment') {
return collectText(node, {
whiteSpace: whiteSpace,
breakBefore: true,
breakAfter: true
})
}
// 1. If this element is not being rendered, or if the user agent is a
// non-CSS user agent, then return the same value as the textContent IDL
// attribute on this element.
//
// Note: were not supporting stylesheets so were acting as if the node
// is rendered.
//
// If you want that behavior use `hast-util-to-string`.
// Important: well have to account for this later though.
// 2. Let results be a new empty list.
results = []
// 3. For each child node node of this element:
while (++index < children.length) {
// 3.1. Let current be the list resulting in running the inner text
// collection steps with node.
// Each item in results will either be a JavaScript string or a
// positive integer (a required line break count).
// 3.2. For each item item in current, append item to results.
results = results.concat(
innerTextCollection(children[index], index, node, {
whiteSpace: whiteSpace,
breakBefore: index ? null : block,
breakAfter:
index < children.length - 1 ? br(children[index + 1]) : block
})
)
}
// 4. Remove any items from results that are the empty string.
// 5. Remove any runs of consecutive required line break count items at the
// start or end of results.
// 6. Replace each remaining run of consecutive required line break count
// items with a string consisting of as many U+000A LINE FEED (LF)
// characters as the maximum of the values in the required line break
// count items.
index = -1
result = []
while (++index < results.length) {
value = results[index]
if (typeof value === 'number') {
if (count !== undefined && value > count) count = value
} else if (value) {
if (count) result.push(repeat('\n', count))
count = 0
result.push(value)
}
}
// 7. Return the concatenation of the string items in results.
return result.join('')
}
// <https://html.spec.whatwg.org/#inner-text-collection-steps>
function innerTextCollection(node, index, parent, options) {
if (node.type === 'element') {
return collectElement(node, index, parent, options)
}
if (node.type === 'text') {
return [
options.whiteSpace === 'normal'
? collectText(node, options)
: collectPreText(node, options)
]
}
return []
}
// Collect an element.
function collectElement(node, _, parent, options) {
// First we infer the `white-space` property.
var whiteSpace = inferWhiteSpace(node, options)
var children = node.children || []
var index = -1
var items = []
var prefix
var suffix
// Were ignoring point 3, and exiting without any content here, because we
// deviated from the spec in `toText` at step 3.
if (notRendered(node)) {
return items
}
// Note: we first detect if there is going to be a break before or after the
// contents, as that changes the white-space handling.
// 2. If nodes computed value of `visibility` is not `visible`, then return
// items.
//
// Note: Ignored, as everything is visible by default user agent styles.
// 3. If node is not being rendered, then return items. [...]
//
// Note: We already did this above.
// See `collectText` for step 4.
// 5. If node is a `<br>` element, then append a string containing a single
// U+000A LINE FEED (LF) character to items.
if (br(node)) {
suffix = '\n'
}
// 7. If nodes computed value of `display` is `table-row`, and nodes CSS
// box is not the last `table-row` box of the nearest ancestor `table`
// box, then append a string containing a single U+000A LINE FEED (LF)
// character to items.
//
// See: <https://html.spec.whatwg.org/#tables-2>
// Note: needs further investigation as this does not account for implicit
// rows.
else if (row(node) && findAfter(parent, node, row)) {
suffix = '\n'
}
// 8. If node is a `<p>` element, then append 2 (a required line break count)
// at the beginning and end of items.
else if (p(node)) {
prefix = 2
suffix = 2
}
// 9. If nodes used value of `display` is block-level or `table-caption`,
// then append 1 (a required line break count) at the beginning and end of
// items.
else if (blockOrCaption(node)) {
prefix = 1
suffix = 1
}
// 1. Let items be the result of running the inner text collection steps with
// each child node of node in tree order, and then concatenating the
// results to a single list.
while (++index < children.length) {
items = items.concat(
innerTextCollection(children[index], index, node, {
whiteSpace: whiteSpace,
breakBefore: index ? null : prefix,
breakAfter:
index < children.length - 1 ? br(children[index + 1]) : suffix
})
)
}
// 6. If nodes computed value of `display` is `table-cell`, and nodes CSS
// box is not the last `table-cell` box of its enclosing `table-row` box,
// then append a string containing a single U+0009 CHARACTER TABULATION
// (tab) character to items.
//
// See: <https://html.spec.whatwg.org/#tables-2>
if (cell(node) && findAfter(parent, node, cell)) {
items.push('\t')
}
// Add the pre- and suffix.
if (prefix) items.unshift(prefix)
if (suffix) items.push(suffix)
return items
}
// 4. If node is a Text node, then for each CSS text box produced by node,
// in content order, compute the text of the box after application of the
// CSS `white-space` processing rules and `text-transform` rules, set
// items to the list of the resulting strings, and return items.
// The CSS `white-space` processing rules are slightly modified:
// collapsible spaces at the end of lines are always collapsed, but they
// are only removed if the line is the last line of the block, or it ends
// with a br element.
// Soft hyphens should be preserved.
//
// Note: See `collectText` and `collectPreText`.
// Note: we dont deal with `text-transform`, no element has that by
// default.
//
// See: <https://drafts.csswg.org/css-text/#white-space-phase-1>
function collectText(node, options) {
var value = String(node.value)
var lines = []
var result = []
var start = 0
var index = -1
var match
var end
var join
while (start < value.length) {
searchLineFeeds.lastIndex = start
match = searchLineFeeds.exec(value)
end = match ? match.index : value.length
lines.push(
// Any sequence of collapsible spaces and tabs immediately preceding or
// following a segment break is removed.
trimAndcollapseSpacesAndTabs(
// [...] ignoring bidi formatting characters (characters with the
// Bidi_Control property [UAX9]: ALM, LTR, RTL, LRE-RLO, LRI-PDI) as if
// they were not there.
value
.slice(start, end)
.replace(/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g, ''),
options.breakBefore,
options.breakAfter
)
)
start = end + 1
}
// Collapsible segment breaks are transformed for rendering according to the
// segment break transformation rules.
// So here we jump to 4.1.2 of [CSSTEXT]:
// Any collapsible segment break immediately following another collapsible
// segment break is removed
while (++index < lines.length) {
// * If the character immediately before or immediately after the segment
// break is the zero-width space character (U+200B), then the break is
// removed, leaving behind the zero-width space.
if (
lines[index].charCodeAt(lines[index].length - 1) === 0x200b /* ZWSP */ ||
(index < lines.length - 1 &&
lines[index + 1].charCodeAt(0) === 0x200b) /* ZWSP */
) {
result.push(lines[index])
join = ''
}
// * Otherwise, if the East Asian Width property [UAX11] of both the
// character before and after the segment break is Fullwidth, Wide, or
// Halfwidth (not Ambiguous), and neither side is Hangul, then the
// segment break is removed.
//
// Note: ignored.
// * Otherwise, if the writing system of the segment break is Chinese,
// Japanese, or Yi, and the character before or after the segment break
// is punctuation or a symbol (Unicode general category P* or S*) and
// has an East Asian Width property of Ambiguous, and the character on
// the other side of the segment break is Fullwidth, Wide, or Halfwidth,
// and not Hangul, then the segment break is removed.
//
// Note: ignored.
// * Otherwise, the segment break is converted to a space (U+0020).
else if (lines[index]) {
if (join) result.push(join)
result.push(lines[index])
join = ' '
}
}
return result.join('')
}
function collectPreText(node) {
return String(node.value)
}
// 3. Every collapsible tab is converted to a collapsible space (U+0020).
// 4. Any collapsible space immediately following another collapsible
// space—even one outside the boundary of the inline containing that
// space, provided both spaces are within the same inline formatting
// context—is collapsed to have zero advance width. (It is invisible,
// but retains its soft wrap opportunity, if any.)
function trimAndcollapseSpacesAndTabs(value, breakBefore, breakAfter) {
var result = []
var start = 0
var match
var end
while (start < value.length) {
searchTabOrSpaces.lastIndex = start
match = searchTabOrSpaces.exec(value)
end = match ? match.index : value.length
// If were not directly after a segment break, but there was white space,
// add an empty value that will be turned into a space.
if (!start && !end && match && !breakBefore) {
result.push('')
}
if (start !== end) {
result.push(value.slice(start, end))
}
start = match ? end + match[0].length : end
}
// If we reached the end, there was trailing white space, and theres no
// segment break after this node, add an empty value that will be turned
// into a space.
if (start !== end && !breakAfter) {
result.push('')
}
return result.join(' ')
}
// We dont support void elements here (so `nobr wbr` -> `normal` is ignored).
function inferWhiteSpace(node, options) {
var props = node.properties || {}
var inherit = options.whiteSpace || 'normal'
switch (node.tagName) {
case 'listing':
case 'plaintext':
case 'xmp':
return 'pre'
case 'nobr':
return 'nowrap'
case 'pre':
return props.wrap ? 'pre-wrap' : 'pre'
case 'td':
case 'th':
return props.noWrap ? 'nowrap' : inherit
case 'textarea':
return 'pre-wrap'
default:
return inherit
}
}
function hidden(node) {
return (node.properties || {}).hidden
}
function closedDialog(node) {
return node.tagName === 'dialog' && !(node.properties || {}).open
}

22
node_modules/hast-util-to-text/license generated vendored Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2019 Titus Wormer <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.

87
node_modules/hast-util-to-text/package.json generated vendored Normal file
View File

@@ -0,0 +1,87 @@
{
"name": "hast-util-to-text",
"version": "2.0.1",
"description": "hast utility to get the plain-text value of a node according to the `innerText` algorithm",
"license": "MIT",
"keywords": [
"unist",
"hast",
"hast-util",
"util",
"utility",
"html",
"string",
"content",
"text",
"innertext"
],
"repository": "syntax-tree/hast-util-to-text",
"bugs": "https://github.com/syntax-tree/hast-util-to-text/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"files": [
"index.js"
],
"dependencies": {
"hast-util-is-element": "^1.0.0",
"repeat-string": "^1.0.0",
"unist-util-find-after": "^3.0.0"
},
"devDependencies": {
"browserify": "^17.0.0",
"hastscript": "^6.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"unist-builder": "^2.0.0",
"xo": "^0.34.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify . -s hastUtilToText -o hast-util-to-text.js",
"build-mangle": "browserify . -s hastUtilToText -p tinyify -o hast-util-to-text.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run format && npm run build && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true,
"esnext": false,
"ignores": [
"hast-util-to-text.js"
],
"rules": {
"unicorn/escape-case": "off",
"no-constant-condition": "off"
}
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
}
}

177
node_modules/hast-util-to-text/readme.md generated vendored Normal file
View File

@@ -0,0 +1,177 @@
# hast-util-to-text
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[**hast**][hast] utility to get the plain-text value of a [*node*][node].
This is like the DOMs `Node#innerText` getter but there are some deviations from
the spec.
The resulting text is returned.
Youd typically want to use [`hast-util-to-string`][to-string]
(`textContent`), but `hast-util-to-text` (`innerText`) adds for example line
breaks where `<br>` elements are used.
## Install
[npm][]:
```sh
npm install hast-util-to-text
```
## Use
```js
var h = require('hastscript')
var toText = require('hast-util-to-text')
var tree = h('div', [
h('h1', {hidden: true}, 'Alpha.'),
h('article', [
h('p', ['Bravo', h('br'), 'charlie.']),
h('p', 'Delta echo \t foxtrot.')
])
])
console.log(toText(tree))
```
Yields:
```txt
Bravo
charlie.
Delta echo foxtrot.
```
## API
### `toText(node)`
Utility to get the plain-text value of a [*node*][node].
* If `node` is a [*comment*][comment], returns its `value`
* If `node` is a [*text*][text], applies normal white-space collapsing to its
`value`, as defined by the [CSS Text][css] spec
* If `node` is a [*root*][root] or [*element*][element], applies an algorithm
similar to the `innerText` getter as defined by [HTML][]
###### Parameters
* `node` ([`Node`][node]) — Thing to stringify
###### Returns
`string` — Stringified `node`.
###### Notes
* If `node` is an [*element*][element] that is not displayed (such as a
`head`), well still use the `innerText` algorithm instead of switching to
`textContent`
* If [*descendants*][descendant] of `node` are [*elements*][element] that are
not displayed, they are ignored
* CSS is not considered, except for the default user agent style sheet
* A line feed is collapsed instead of ignored in cases where Fullwidth, Wide,
or Halfwidth East Asian Width characters are used, the same goes for a case
with Chinese, Japanese, or Yi writing systems
* Replaced [*elements*][element] (such as `audio`) are treated like
non-replaced *elements*
## Security
`hast-util-to-text` does not change the syntax tree so there are no
openings for [cross-site scripting (XSS)][xss] attacks.
## Related
* [`hast-util-to-string`](https://github.com/rehypejs/rehype-minify/tree/HEAD/packages/hast-util-to-string)
— Get the plain-text value (`textContent`)
* [`hast-util-from-text`](https://github.com/syntax-tree/hast-util-from-text)
— Set the plain-text value (`innerText`)
* [`hast-util-from-string`](https://github.com/rehypejs/rehype-minify/tree/HEAD/packages/hast-util-from-string)
— Set the plain-text value (`textContent`)
## Contribute
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://img.shields.io/travis/syntax-tree/hast-util-to-text.svg
[build]: https://travis-ci.org/syntax-tree/hast-util-to-text
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-text.svg
[coverage]: https://codecov.io/github/syntax-tree/hast-util-to-text
[downloads-badge]: https://img.shields.io/npm/dm/hast-util-to-text.svg
[downloads]: https://www.npmjs.com/package/hast-util-to-text
[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-to-text.svg
[size]: https://bundlephobia.com/result?p=hast-util-to-text
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/syntax-tree/unist/discussions
[npm]: https://docs.npmjs.com/cli/install
[license]: license
[author]: https://wooorm.com
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
[html]: https://html.spec.whatwg.org/#the-innertext-idl-attribute
[css]: https://drafts.csswg.org/css-text/#white-space-phase-1
[to-string]: https://github.com/rehypejs/rehype-minify/tree/HEAD/packages/hast-util-to-string
[descendant]: https://github.com/syntax-tree/unist#descendant
[hast]: https://github.com/syntax-tree/hast
[node]: https://github.com/syntax-tree/hast#nodes
[root]: https://github.com/syntax-tree/hast#root
[comment]: https://github.com/syntax-tree/hast#comment
[text]: https://github.com/syntax-tree/hast#text
[element]: https://github.com/syntax-tree/hast#element
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting