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

126
node_modules/hast-util-to-mdast/index.js generated vendored Normal file
View File

@@ -0,0 +1,126 @@
'use strict'
module.exports = toMdast
var has = require('hast-util-has-property')
var minify = require('rehype-minify-whitespace')
var convert = require('unist-util-is/convert')
var visit = require('unist-util-visit')
var xtend = require('xtend')
var one = require('./lib/one')
var handlers = require('./lib/handlers')
var own = require('./lib/util/own')
var block = convert(['heading', 'paragraph', 'root'])
function toMdast(tree, options) {
var settings = options || {}
var byId = {}
var mdast
h.nodeById = byId
h.baseFound = false
h.frozenBaseUrl = null
h.wrapText = true
h.qNesting = 0
h.handlers = settings.handlers ? xtend(handlers, settings.handlers) : handlers
h.augment = augment
h.document = settings.document
h.checked = settings.checked || '[x]'
h.unchecked = settings.unchecked || '[ ]'
h.quotes = settings.quotes || ['"']
visit(tree, 'element', onelement)
minify({newlines: settings.newlines === true})(tree)
mdast = one(h, tree, null)
visit(mdast, 'text', ontext)
return mdast
function h(node, type, props, children) {
var result
if (
!children &&
(typeof props === 'string' ||
(typeof props === 'object' && 'length' in props))
) {
children = props
props = {}
}
result = xtend({type: type}, props)
if (typeof children === 'string') {
result.value = children
} else if (children) {
result.children = children
}
return augment(node, result)
}
// To do: inline in a future major.
// `right` is the finalized mdast node, created from `left`, a hast node.
function augment(left, right) {
if (left.position) {
right.position = left.position
}
return right
}
function onelement(node) {
var id = has(node, 'id') && String(node.properties.id).toUpperCase()
if (id && !own.call(byId, id)) {
byId[id] = node
}
}
// Collapse text nodes, and fix whitespace.
// Most of this is taken care of by `rehype-minify-whitespace`, but
// were generating some whitespace too, and some nodes are in the end
// ignored.
// So clean up:
function ontext(node, index, parent) {
var previous = parent.children[index - 1]
if (previous && node.type === previous.type) {
previous.value += node.value
parent.children.splice(index, 1)
if (previous.position && node.position) {
previous.position.end = node.position.end
}
// Iterate over the previous node again, to handle its total value.
return index - 1
}
node.value = node.value.replace(/[\t ]*(\r?\n|\r)[\t ]*/, '$1')
// We dont care about other phrasing nodes in between (e.g., `[ asd ]()`),
// as there the whitespace matters.
if (block(parent)) {
if (!index) {
node.value = node.value.replace(/^[\t ]+/, '')
}
if (index === parent.children.length - 1) {
node.value = node.value.replace(/[\t ]+$/, '')
}
}
if (!node.value) {
parent.children.splice(index, 1)
return index
}
}
}

22
node_modules/hast-util-to-mdast/lib/all.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
'use strict'
module.exports = all
var one = require('./one')
function all(h, parent) {
var nodes = parent.children || []
var values = []
var index = -1
var result
while (++index < nodes.length) {
result = one(h, nodes[index], parent)
if (result) {
values = values.concat(result)
}
}
return values
}

10
node_modules/hast-util-to-mdast/lib/handlers/base.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
'use strict'
module.exports = base
function base(h, node) {
if (!h.baseFound) {
h.frozenBaseUrl = node.properties.href
h.baseFound = true
}
}

View File

@@ -0,0 +1,9 @@
'use strict'
module.exports = blockquote
var wrapChildren = require('../util/wrap-children')
function blockquote(h, node) {
return h(node, 'blockquote', wrapChildren(h, node))
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = br
function br(h, node) {
return h.wrapText ? h(node, 'break') : h(node, 'text', ' ')
}

48
node_modules/hast-util-to-mdast/lib/handlers/code.js generated vendored Normal file
View File

@@ -0,0 +1,48 @@
'use strict'
module.exports = code
var has = require('hast-util-has-property')
var convert = require('hast-util-is-element/convert')
var toText = require('hast-util-to-text')
var trim = require('trim-trailing-lines')
var wrapText = require('../util/wrap-text')
var prefix = 'language-'
var pre = convert('pre')
var isCode = convert('code')
function code(h, node) {
var children = node.children
var index = -1
var classList
var lang
if (pre(node)) {
while (++index < children.length) {
if (isCode(children[index]) && has(children[index], 'className')) {
classList = children[index].properties.className
break
}
}
}
if (classList) {
index = -1
while (++index < classList.length) {
if (classList[index].slice(0, prefix.length) === prefix) {
lang = classList[index].slice(prefix.length)
break
}
}
}
return h(
node,
'code',
{lang: lang || null, meta: null},
trim(wrapText(h, toText(node)))
)
}

View File

@@ -0,0 +1,9 @@
'use strict'
module.exports = comment
var wrapText = require('../util/wrap-text')
function comment(h, node) {
return h(node, 'html', '<!--' + wrapText(h, node.value) + '-->')
}

View File

@@ -0,0 +1,9 @@
'use strict'
module.exports = del
var all = require('../all')
function del(h, node) {
return h(node, 'delete', all(h, node))
}

98
node_modules/hast-util-to-mdast/lib/handlers/dl.js generated vendored Normal file
View File

@@ -0,0 +1,98 @@
'use strict'
module.exports = dl
var convert = require('hast-util-is-element/convert')
var spread = require('../util/list-items-spread')
var wrapListItems = require('../util/wrap-list-items')
var div = convert('div')
var dt = convert('dt')
var dd = convert('dd')
function dl(h, node) {
var children = node.children
var index = -1
var clean = []
var groups = []
var group = {titles: [], definitions: []}
var content
var child
// Unwrap `<div>`s
while (++index < children.length) {
child = children[index]
clean = clean.concat(div(child) ? child.children : child)
}
index = -1
// Group titles and definitions.
while (++index < clean.length) {
child = clean[index]
if (dt(child)) {
if (dd(clean[index - 1])) {
groups.push(group)
group = {titles: [], definitions: []}
}
group.titles.push(child)
} else {
group.definitions.push(child)
}
}
groups.push(group)
// Create items.
index = -1
content = []
while (++index < groups.length) {
group = handle(h, groups[index].titles).concat(
handle(h, groups[index].definitions)
)
if (group.length) {
content.push({
type: 'listItem',
spread: group.length > 1,
checked: null,
children: group
})
}
}
// Create a list if there are items.
if (content.length) {
return h(
node,
'list',
{ordered: false, start: null, spread: spread(content)},
content
)
}
}
function handle(h, children) {
var nodes = wrapListItems(h, {children: children})
if (!nodes.length) {
return nodes
}
if (nodes.length === 1) {
return nodes[0].children
}
return [
{
type: 'list',
ordered: false,
start: null,
spread: spread(nodes),
children: nodes
}
]
}

View File

@@ -0,0 +1,9 @@
'use strict'
module.exports = emphasis
var all = require('../all')
function emphasis(h, node) {
return h(node, 'emphasis', all(h, node))
}

View File

@@ -0,0 +1,18 @@
'use strict'
module.exports = heading
var all = require('../all')
function heading(h, node) {
/* istanbul ignore next - `else` shouldnt happen, of course… */
var depth = Number(node.tagName.charAt(1)) || 1
var wrap = h.wrapText
var result
h.wrapText = false
result = h(node, 'heading', {depth: depth}, all(h, node))
h.wrapText = wrap
return result
}

24
node_modules/hast-util-to-mdast/lib/handlers/iframe.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
'use strict'
module.exports = iframe
var resolve = require('../util/resolve')
var wrapText = require('../util/wrap-text')
function iframe(h, node) {
var src = node.properties.src
var title = node.properties.title
// Only create a link if there is a title.
// We cant use the content of the frame because conforming HTML parsers treat
// it as text, whereas legacy parsers treat it as HTML, so it will likely
// contain tags that will show up in text.
if (src && title) {
return {
type: 'link',
title: null,
url: resolve(h, src),
children: [{type: 'text', value: wrapText(h, title)}]
}
}
}

13
node_modules/hast-util-to-mdast/lib/handlers/image.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
'use strict'
module.exports = image
var resolve = require('../util/resolve')
function image(h, node) {
return h(node, 'image', {
url: resolve(h, node.properties.src),
title: node.properties.title || null,
alt: node.properties.alt || ''
})
}

191
node_modules/hast-util-to-mdast/lib/handlers/index.js generated vendored Normal file
View File

@@ -0,0 +1,191 @@
'use strict'
var all = require('../all')
var wrapped = require('../util/wrap-children')
var base = require('./base')
var blockquote = require('./blockquote')
var br = require('./break')
var code = require('./code')
var comment = require('./comment')
var del = require('./delete')
var dl = require('./dl')
var emphasis = require('./emphasis')
var heading = require('./heading')
var iframe = require('./iframe')
var image = require('./image')
var inlineCode = require('./inline-code')
var input = require('./input')
var link = require('./link')
var listItem = require('./list-item')
var list = require('./list')
var media = require('./media')
var paragraph = require('./paragraph')
var quote = require('./q')
var root = require('./root')
var select = require('./select')
var strong = require('./strong')
var cell = require('./table-cell')
var row = require('./table-row')
var table = require('./table')
var text = require('./text')
var textarea = require('./textarea')
var thematicBreak = require('./thematic-break')
var wbr = require('./wbr')
exports.root = root
exports.text = text
exports.comment = comment
exports.doctype = ignore
exports.applet = ignore
exports.area = ignore
exports.basefont = ignore
exports.bgsound = ignore
exports.caption = ignore
exports.col = ignore
exports.colgroup = ignore
exports.command = ignore
exports.content = ignore
exports.datalist = ignore
exports.dialog = ignore
exports.element = ignore
exports.embed = ignore
exports.frame = ignore
exports.frameset = ignore
exports.isindex = ignore
exports.keygen = ignore
exports.link = ignore
exports.math = ignore
exports.menu = ignore
exports.menuitem = ignore
exports.meta = ignore
exports.nextid = ignore
exports.noembed = ignore
exports.noframes = ignore
exports.optgroup = ignore
exports.option = ignore
exports.param = ignore
exports.script = ignore
exports.shadow = ignore
exports.source = ignore
exports.spacer = ignore
exports.style = ignore
exports.svg = ignore
exports.template = ignore
exports.title = ignore
exports.track = ignore
exports.abbr = all
exports.acronym = all
exports.bdi = all
exports.bdo = all
exports.big = all
exports.blink = all
exports.button = all
exports.canvas = all
exports.cite = all
exports.data = all
exports.details = all
exports.dfn = all
exports.font = all
exports.ins = all
exports.label = all
exports.map = all
exports.marquee = all
exports.meter = all
exports.nobr = all
exports.noscript = all
exports.object = all
exports.output = all
exports.progress = all
exports.rb = all
exports.rbc = all
exports.rp = all
exports.rt = all
exports.rtc = all
exports.ruby = all
exports.slot = all
exports.small = all
exports.span = all
exports.sup = all
exports.sub = all
exports.tbody = all
exports.tfoot = all
exports.thead = all
exports.time = all
exports.address = wrapped
exports.article = wrapped
exports.aside = wrapped
exports.body = wrapped
exports.center = wrapped
exports.div = wrapped
exports.fieldset = wrapped
exports.figcaption = wrapped
exports.figure = wrapped
exports.form = wrapped
exports.footer = wrapped
exports.header = wrapped
exports.hgroup = wrapped
exports.html = wrapped
exports.legend = wrapped
exports.main = wrapped
exports.multicol = wrapped
exports.nav = wrapped
exports.picture = wrapped
exports.section = wrapped
exports.a = link
exports.audio = media
exports.b = strong
exports.base = base
exports.blockquote = blockquote
exports.br = br
exports.code = inlineCode
exports.dir = list
exports.dl = dl
exports.dt = listItem
exports.dd = listItem
exports.del = del
exports.em = emphasis
exports.h1 = heading
exports.h2 = heading
exports.h3 = heading
exports.h4 = heading
exports.h5 = heading
exports.h6 = heading
exports.hr = thematicBreak
exports.i = emphasis
exports.iframe = iframe
exports.img = image
exports.image = image
exports.input = input
exports.kbd = inlineCode
exports.li = listItem
exports.listing = code
exports.mark = emphasis
exports.ol = list
exports.p = paragraph
exports.plaintext = code
exports.pre = code
exports.q = quote
exports.s = del
exports.samp = inlineCode
exports.select = select
exports.strike = del
exports.strong = strong
exports.summary = paragraph
exports.table = table
exports.td = cell
exports.textarea = textarea
exports.th = cell
exports.tr = row
exports.tt = inlineCode
exports.u = emphasis
exports.ul = list
exports.var = inlineCode
exports.video = media
exports.wbr = wbr
exports.xmp = code
function ignore() {}

View File

@@ -0,0 +1,10 @@
'use strict'
module.exports = inlineCode
var toText = require('hast-util-to-text')
var wrapText = require('../util/wrap-text')
function inlineCode(h, node) {
return h(node, 'inlineCode', wrapText(h, toText(node)))
}

105
node_modules/hast-util-to-mdast/lib/handlers/input.js generated vendored Normal file
View File

@@ -0,0 +1,105 @@
'use strict'
module.exports = input
var convert = require('hast-util-is-element/convert')
var repeat = require('repeat-string')
var findSelectedOptions = require('../util/find-selected-options')
var own = require('../util/own')
var resolve = require('../util/resolve')
var wrapText = require('../util/wrap-text')
var datalist = convert('datalist')
function input(h, node) {
var props = node.properties
var value = props.value || props.placeholder
var results = []
var values = []
var index = -1
var list
if (props.disabled || props.type === 'hidden' || props.type === 'file') {
return
}
if (props.type === 'checkbox' || props.type === 'radio') {
return h(
node,
'text',
wrapText(h, h[props.checked ? 'checked' : 'unchecked'])
)
}
if (props.type === 'image') {
return props.alt || value
? h(node, 'image', {
url: resolve(h, props.src),
title: (props.title && wrapText(h, props.title)) || null,
alt: wrapText(h, props.alt || value)
})
: []
}
if (value) {
values = [[value]]
} else if (
// `list` is not supported on these types:
props.type !== 'password' &&
props.type !== 'file' &&
props.type !== 'submit' &&
props.type !== 'reset' &&
props.type !== 'button' &&
props.list
) {
list = String(props.list).toUpperCase()
if (own.call(h.nodeById, list) && datalist(h.nodeById[list])) {
values = findSelectedOptions(h, h.nodeById[list], props)
}
}
if (!values.length) {
return
}
// Hide password value.
if (props.type === 'password') {
// Passwords dont support `list`.
values[0] = [repeat('•', values[0][0].length)]
}
if (props.type === 'url' || props.type === 'email') {
while (++index < values.length) {
value = resolve(h, values[index][0])
results.push(
h(
node,
'link',
{
title: null,
url: wrapText(h, props.type === 'email' ? 'mailto:' + value : value)
},
[{type: 'text', value: wrapText(h, values[index][1] || value)}]
)
)
if (index !== values.length - 1) {
results.push({type: 'text', value: ', '})
}
}
return results
}
while (++index < values.length) {
results.push(
values[index][1]
? values[index][1] + ' (' + values[index][0] + ')'
: values[index][0]
)
}
return h(node, 'text', wrapText(h, results.join(', ')))
}

18
node_modules/hast-util-to-mdast/lib/handlers/link.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
'use strict'
module.exports = link
var all = require('../all')
var resolve = require('../util/resolve')
function link(h, node) {
return h(
node,
'link',
{
title: node.properties.title || null,
url: resolve(h, node.properties.href)
},
all(h, node)
)
}

View File

@@ -0,0 +1,45 @@
'use strict'
module.exports = listItem
var convert = require('hast-util-is-element/convert')
var shallow = require('../util/shallow')
var wrapChildren = require('../util/wrap-children')
var p = convert('p')
var input = convert('input')
function listItem(h, node) {
var head = node.children[0]
var checked = null
var content
var checkbox
var clone
var headClone
// Check if this node starts with a checkbox.
if (p(head)) {
checkbox = head.children[0]
if (
input(checkbox) &&
(checkbox.properties.type === 'checkbox' ||
checkbox.properties.type === 'radio')
) {
checked = Boolean(checkbox.properties.checked)
headClone = shallow(head)
headClone.children = head.children.slice(1)
clone = shallow(node)
clone.children = [headClone].concat(node.children.slice(1))
}
}
content = wrapChildren(h, clone || node)
return h(
node,
'listItem',
{spread: content.length > 1, checked: checked},
content
)
}

27
node_modules/hast-util-to-mdast/lib/handlers/list.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
'use strict'
module.exports = list
var convert = require('hast-util-is-element/convert')
var has = require('hast-util-has-property')
var spread = require('../util/list-items-spread')
var wrapListItems = require('../util/wrap-list-items')
var ol = convert('ol')
function list(h, node) {
var ordered = ol(node)
var children = wrapListItems(h, node)
var start = null
if (ordered) {
start = has(node, 'start') ? node.properties.start : 1
}
return h(
node,
'list',
{ordered: ordered, start: start, spread: spread(children)},
children
)
}

60
node_modules/hast-util-to-mdast/lib/handlers/media.js generated vendored Normal file
View File

@@ -0,0 +1,60 @@
'use strict'
module.exports = media
var convert = require('hast-util-is-element/convert')
var toString = require('mdast-util-to-string')
var visit = require('unist-util-visit')
var all = require('../all')
var resolve = require('../util/resolve')
var wrap = require('../util/wrap')
var source = convert('source')
var video = convert('video')
function media(h, node) {
var nodes = all(h, node)
var poster = video(node) && node.properties.poster
var src = node.properties.src
var index = -1
var linkInFallbackContent
visit({type: 'root', children: nodes}, 'link', findLink)
// If the content links to something, or if its not phrasing…
if (linkInFallbackContent || wrap.needed(nodes)) {
return nodes
}
// Find the source.
while (!src && ++index < node.children.length) {
if (source(node.children[index])) {
src = node.children[index].properties.src
}
}
// If theres a poster defined on the video, create an image.
if (poster) {
nodes = [
{
type: 'image',
title: null,
url: resolve(h, poster),
alt: toString({children: nodes})
}
]
}
// Link to the media resource.
return {
type: 'link',
title: node.properties.title || null,
url: resolve(h, src),
children: nodes
}
function findLink() {
linkInFallbackContent = true
return visit.EXIT
}
}

View File

@@ -0,0 +1,13 @@
'use strict'
module.exports = paragraph
var all = require('../all')
function paragraph(h, node) {
var nodes = all(h, node)
if (nodes.length) {
return h(node, 'paragraph', nodes)
}
}

23
node_modules/hast-util-to-mdast/lib/handlers/q.js generated vendored Normal file
View File

@@ -0,0 +1,23 @@
'use strict'
module.exports = q
var all = require('../all')
function q(h, node) {
var expected = h.quotes[h.qNesting % h.quotes.length]
var contents
h.qNesting++
contents = all(h, node)
h.qNesting--
contents.unshift({type: 'text', value: expected.charAt(0)})
contents.push({
type: 'text',
value: expected.length > 1 ? expected.charAt(1) : expected
})
return contents
}

16
node_modules/hast-util-to-mdast/lib/handlers/root.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
'use strict'
module.exports = root
var all = require('../all')
var wrap = require('../util/wrap')
function root(h, node) {
var children = all(h, node)
if (h.document || wrap.needed(children)) {
children = wrap(children)
}
return h(node, 'root', children)
}

22
node_modules/hast-util-to-mdast/lib/handlers/select.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
'use strict'
module.exports = select
var findSelectedOptions = require('../util/find-selected-options')
var wrapText = require('../util/wrap-text')
function select(h, node) {
var values = findSelectedOptions(h, node)
var index = -1
var results = []
var value
while (++index < values.length) {
value = values[index]
results.push(value[1] ? value[1] + ' (' + value[0] + ')' : value[0])
}
if (results.length) {
return h(node, 'text', wrapText(h, results.join(', ')))
}
}

View File

@@ -0,0 +1,9 @@
'use strict'
module.exports = strong
var all = require('../all')
function strong(h, node) {
return h(node, 'strong', all(h, node))
}

View File

@@ -0,0 +1,16 @@
'use strict'
module.exports = cell
var all = require('../all')
function cell(h, node) {
var wrap = h.wrapText
var result
h.wrapText = false
result = h(node, 'tableCell', all(h, node))
h.wrapText = wrap
return result
}

View File

@@ -0,0 +1,9 @@
'use strict'
module.exports = row
var all = require('../all')
function row(h, node) {
return h(node, 'tableRow', all(h, node))
}

135
node_modules/hast-util-to-mdast/lib/handlers/table.js generated vendored Normal file
View File

@@ -0,0 +1,135 @@
'use strict'
module.exports = table
var convert = require('hast-util-is-element/convert')
var visit = require('unist-util-visit')
var all = require('../all')
var thead = convert('thead')
var tr = convert('tr')
var cell = convert(['th', 'td'])
function table(h, node) {
var info = inspect(node)
return h(node, 'table', {align: info.align}, toRows(all(h, node), info))
}
// Infer whether the HTML table has a head and how it aligns.
function inspect(node) {
var headless = true
var align = [null]
var rowIndex = 0
var cellIndex = 0
visit(node, 'element', visitor)
return {align: align, headless: headless}
function visitor(child) {
// If there is a `thead`, assume there is a header row.
if (thead(child)) {
headless = false
} else if (tr(child)) {
rowIndex++
cellIndex = 0
} else if (cell(child)) {
if (!align[cellIndex]) {
align[cellIndex] = child.properties.align || null
}
// If there is a th in the first row, assume there is a header row.
if (headless && rowIndex < 2 && child.tagName === 'th') {
headless = false
}
cellIndex++
}
}
}
// Ensure the rows are properly structured.
function toRows(children, info) {
var nodes = []
var index = -1
var node
var queue
// Add an empty header row.
if (info.headless) {
nodes.push({type: 'tableRow', children: []})
}
while (++index < children.length) {
node = children[index]
if (node.type === 'tableRow') {
if (queue) {
node.children = queue.concat(node.children)
queue = undefined
}
nodes.push(node)
} else {
if (!queue) queue = []
queue.push(node)
}
}
if (queue) {
node = nodes[nodes.length - 1]
node.children = node.children.concat(queue)
}
index = -1
while (++index < nodes.length) {
node = nodes[index]
node.children = toCells(node.children, info)
}
return nodes
}
// Ensure the cells in a row are properly structured.
function toCells(children, info) {
var nodes = []
var index = -1
var node
var queue
while (++index < children.length) {
node = children[index]
if (node.type === 'tableCell') {
if (queue) {
node.children = queue.concat(node.children)
queue = undefined
}
nodes.push(node)
} else {
if (!queue) queue = []
queue.push(node)
}
}
if (queue) {
node = nodes[nodes.length - 1]
if (!node) {
node = {type: 'tableCell', children: []}
nodes.push(node)
}
node.children = node.children.concat(queue)
}
index = nodes.length - 1
while (++index < info.align.length) {
nodes.push({type: 'tableCell', children: []})
}
return nodes
}

9
node_modules/hast-util-to-mdast/lib/handlers/text.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
'use strict'
module.exports = text
var wrapText = require('../util/wrap-text')
function text(h, node) {
return h(node, 'text', wrapText(h, node.value))
}

View File

@@ -0,0 +1,10 @@
'use strict'
module.exports = textarea
var toText = require('hast-util-to-text')
var wrapText = require('../util/wrap-text')
function textarea(h, node) {
return h(node, 'text', wrapText(h, toText(node)))
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = thematicBreak
function thematicBreak(h, node) {
return h(node, 'thematicBreak')
}

7
node_modules/hast-util-to-mdast/lib/handlers/wbr.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = wbr
function wbr(h, node) {
return h(node, 'text', '\u200b')
}

33
node_modules/hast-util-to-mdast/lib/one.js generated vendored Normal file
View File

@@ -0,0 +1,33 @@
'use strict'
module.exports = one
var all = require('./all')
var own = require('./util/own')
var wrapText = require('./util/wrap-text')
function one(h, node, parent) {
var fn
if (node.type === 'element') {
if (node.properties && node.properties.dataMdast === 'ignore') {
return
}
if (own.call(h.handlers, node.tagName)) {
fn = h.handlers[node.tagName]
}
} else if (own.call(h.handlers, node.type)) {
fn = h.handlers[node.type]
}
return (typeof fn === 'function' ? fn : unknown)(h, node, parent)
}
function unknown(h, node) {
if (node.value) {
return h(node, 'text', wrapText(h, node.value))
}
return all(h, node)
}

View File

@@ -0,0 +1,66 @@
'use strict'
var has = require('hast-util-has-property')
var convert = require('hast-util-is-element/convert')
var toText = require('hast-util-to-text')
var wrapText = require('./wrap-text')
module.exports = findSelectedOptions
var option = convert('option')
function findSelectedOptions(h, node, properties) {
var props = properties || node.properties
var options = findOptions(node)
var size = Math.min(parseInt(props.size, 10), 0) || (props.multiple ? 4 : 1)
var index = -1
var selectedOptions = []
var values = []
var option
var list
var content
var label
var value
while (++index < options.length) {
if (has(options[index], 'selected')) {
selectedOptions.push(options[index])
}
}
list = selectedOptions.length ? selectedOptions : options
options = list.slice(0, size)
index = -1
while (++index < options.length) {
option = options[index]
content = wrapText(h, toText(option))
label = content || option.properties.label
value = option.properties.value || content
values.push([value, label === value ? null : label])
}
return values
}
function findOptions(node) {
var children = node.children
var index = -1
var results = []
var child
while (++index < children.length) {
child = children[index]
if (option(child)) {
if (!has(child, 'disabled')) {
results.push(child)
}
} else if (child.children) {
results = results.concat(findOptions(child))
}
}
return results
}

View File

@@ -0,0 +1,17 @@
'use strict'
module.exports = spread
function spread(children) {
var index = -1
if (children.length > 1) {
while (++index < children.length) {
if (children[index].spread) {
return true
}
}
}
return false
}

3
node_modules/hast-util-to-mdast/lib/util/own.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
'use strict'
module.exports = {}.hasOwnProperty

16
node_modules/hast-util-to-mdast/lib/util/resolve.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
'use strict'
module.exports = resolve
function resolve(h, url) {
if (url === null || url === undefined) {
return ''
}
/* istanbul ignore next - ignored for older Node */
if (h.frozenBaseUrl && typeof URL !== 'undefined') {
return String(new URL(url, h.frozenBaseUrl))
}
return url
}

19
node_modules/hast-util-to-mdast/lib/util/shallow.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
'use strict'
module.exports = shallow
var own = require('./own')
// Shallow copy of a node, excluding its children.
function shallow(node) {
var copy = {}
var key
for (key in node) {
if (own.call(node, key) && key !== 'children') {
copy[key] = node[key]
}
}
return copy
}

View File

@@ -0,0 +1,10 @@
'use strict'
module.exports = wrapped
var all = require('../all')
var wrap = require('./wrap')
function wrapped(h, node) {
return wrap(all(h, node))
}

View File

@@ -0,0 +1,23 @@
'use strict'
module.exports = wrapListItems
var all = require('../all')
function wrapListItems(h, node) {
var children = all(h, node)
var index = -1
while (++index < children.length) {
if (children[index].type !== 'listItem') {
children[index] = {
type: 'listItem',
spread: false,
checked: null,
children: [children[index]]
}
}
}
return children
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = wrapText
function wrapText(h, value) {
return h.wrapText ? value : value.replace(/\r?\n|\r/g, ' ')
}

133
node_modules/hast-util-to-mdast/lib/util/wrap.js generated vendored Normal file
View File

@@ -0,0 +1,133 @@
'use strict'
module.exports = wrap
wrap.needed = needed
var extend = require('extend')
var phrasing = require('mdast-util-phrasing')
var shallow = require('./shallow')
function wrap(nodes) {
return runs(nodes, onphrasing)
function onphrasing(nodes) {
var head = nodes[0]
if (
nodes.length === 1 &&
head.type === 'text' &&
(head.value === ' ' || head.value === '\n')
) {
return []
}
return {type: 'paragraph', children: nodes}
}
}
// Wrap all runs of mdast phrasing content in `paragraph` nodes.
function runs(nodes, onphrasing, onnonphrasing) {
var nonphrasing = onnonphrasing || identity
var flattened = flatten(nodes)
var result = []
var index = -1
var node
var queue
while (++index < flattened.length) {
node = flattened[index]
if (phrasing(node)) {
if (!queue) queue = []
queue.push(node)
} else {
if (queue) {
result = result.concat(onphrasing(queue))
queue = undefined
}
result = result.concat(nonphrasing(node))
}
}
if (queue) {
result = result.concat(onphrasing(queue))
}
return result
}
// Flatten a list of nodes.
function flatten(nodes) {
var flattened = []
var index = -1
var node
while (++index < nodes.length) {
node = nodes[index]
// Straddling: some elements are *weird*.
// Namely: `map`, `ins`, `del`, and `a`, as they are hybrid elements.
// See: <https://html.spec.whatwg.org/#paragraphs>.
// Paragraphs are the weirdest of them all.
// See the straddling fixture for more info!
// `ins` is ignored in mdast, so we dont need to worry about that.
// `map` maps to its content, so we dont need to worry about that either.
// `del` maps to `delete` and `a` to `link`, so we do handle those.
// What well do is split `node` over each of its children.
if (
(node.type === 'delete' || node.type === 'link') &&
needed(node.children)
) {
flattened = flattened.concat(split(node))
} else {
flattened.push(node)
}
}
return flattened
}
// Check if there are non-phrasing mdast nodes returned.
// This is needed if a fragment is given, which could just be a sentence, and
// doesnt need a wrapper paragraph.
function needed(nodes) {
var index = -1
var node
while (++index < nodes.length) {
node = nodes[index]
if (!phrasing(node) || (node.children && needed(node.children))) {
return true
}
}
}
function split(node) {
return runs(node.children, onphrasing, onnonphrasing)
// Use `child`, add `parent` as its first child, put the original children
// into `parent`.
function onnonphrasing(child) {
var parent = extend(true, {}, shallow(node))
var copy = shallow(child)
copy.children = [parent]
parent.children = child.children
return copy
}
// Use `parent`, put the phrasing run inside it.
function onphrasing(nodes) {
var parent = extend(true, {}, shallow(node))
parent.children = nodes
return parent
}
}
function identity(n) {
return n
}

23
node_modules/hast-util-to-mdast/license generated vendored Normal file
View File

@@ -0,0 +1,23 @@
(The MIT License)
Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
Copyright (c) 2016 Seth Vincent <sethvincent@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.

View File

@@ -0,0 +1,4 @@
module.exports = identity
function identity(d) {
return d
}

View File

@@ -0,0 +1,4 @@
module.exports = color
function color(d) {
return '\u001B[33m' + d + '\u001B[39m'
}

View File

@@ -0,0 +1,93 @@
'use strict'
module.exports = visitParents
var convert = require('unist-util-is/convert')
var color = require('./color')
var CONTINUE = true
var SKIP = 'skip'
var EXIT = false
visitParents.CONTINUE = CONTINUE
visitParents.SKIP = SKIP
visitParents.EXIT = EXIT
function visitParents(tree, test, visitor, reverse) {
var step
var is
if (typeof test === 'function' && typeof visitor !== 'function') {
reverse = visitor
visitor = test
test = null
}
is = convert(test)
step = reverse ? -1 : 1
factory(tree, null, [])()
function factory(node, index, parents) {
var value = typeof node === 'object' && node !== null ? node : {}
var name
if (typeof value.type === 'string') {
name =
typeof value.tagName === 'string'
? value.tagName
: typeof value.name === 'string'
? value.name
: undefined
visit.displayName =
'node (' + color(value.type + (name ? '<' + name + '>' : '')) + ')'
}
return visit
function visit() {
var grandparents = parents.concat(node)
var result = []
var subresult
var offset
if (!test || is(node, index, parents[parents.length - 1] || null)) {
result = toResult(visitor(node, parents))
if (result[0] === EXIT) {
return result
}
}
if (node.children && result[0] !== SKIP) {
offset = (reverse ? node.children.length : -1) + step
while (offset > -1 && offset < node.children.length) {
subresult = factory(node.children[offset], offset, grandparents)()
if (subresult[0] === EXIT) {
return subresult
}
offset =
typeof subresult[1] === 'number' ? subresult[1] : offset + step
}
}
return result
}
}
}
function toResult(value) {
if (value !== null && typeof value === 'object' && 'length' in value) {
return value
}
if (typeof value === 'number') {
return [CONTINUE, value]
}
return [value]
}

View File

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

View File

@@ -0,0 +1,104 @@
{
"name": "unist-util-visit-parents",
"version": "3.1.1",
"description": "unist utility to recursively walk over nodes, with ancestral information",
"license": "MIT",
"keywords": [
"unist",
"unist-util",
"util",
"utility",
"tree",
"ast",
"visit",
"traverse",
"walk",
"check",
"parent",
"parents"
],
"repository": "syntax-tree/unist-util-visit-parents",
"bugs": "https://github.com/syntax-tree/unist-util-visit-parents/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)"
],
"browser": {
"./color.js": "./color.browser.js"
},
"react-native": {
"./color.js": "./color.browser.js"
},
"files": [
"index.js",
"color.js",
"color.browser.js",
"types/index.d.ts"
],
"types": "types/index.d.ts",
"dependencies": {
"@types/unist": "^2.0.0",
"unist-util-is": "^4.0.0"
},
"devDependencies": {
"browserify": "^17.0.0",
"dtslint": "^4.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark": "^13.0.0",
"remark-cli": "^9.0.0",
"remark-gfm": "^1.0.0",
"remark-preset-wooorm": "^8.0.0",
"strip-ansi": "^6.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"typescript": "^4.0.0",
"unified": "^9.0.0",
"xo": "^0.34.0"
},
"scripts": {
"format": "remark . -qfo && prettier . --write && xo --fix",
"build-bundle": "browserify index.js -s unistUtilVisitParents > unist-util-visit-parents.js",
"build-mangle": "browserify index.js -s unistUtilVisitParents -p tinyify > unist-util-visit-parents.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test-types": "dtslint types",
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
},
"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,
"rules": {
"unicorn/prefer-set-has": "off",
"unicorn/prefer-reflect-apply": "off"
},
"ignores": [
"types/",
"unist-util-visit-parents.js"
]
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
}
}

View File

@@ -0,0 +1,233 @@
# unist-util-visit-parents
[![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]
[**unist**][unist] utility to visit nodes, with ancestral information.
## Install
[npm][]:
```sh
npm install unist-util-visit-parents
```
## Use
```js
var remark = require('remark')
var visit = require('unist-util-visit-parents')
var tree = remark.parse('Some _emphasis_, **importance**, and `code`.')
visit(tree, 'strong', visitor)
function visitor(node, ancestors) {
console.log(ancestors)
}
```
Yields:
```js
[ { type: 'root', children: [ [Object] ] },
{ type: 'paragraph',
children:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ] } ]
```
## API
### `visit(tree[, test], visitor[, reverse])`
Visit nodes ([*inclusive descendants*][descendant] of [`tree`][tree]), with
ancestral information.
Optionally filtering nodes.
Optionally in reverse.
This algorithm performs [*depth-first*][depth-first]
[*tree traversal*][tree-traversal] in [*preorder*][preorder] (**NLR**), or
if `reverse` is given, in *reverse preorder* (**NRL**).
Walking the tree is an intensive task.
Make use of the return values of the visitor when possible.
Instead of walking a tree multiple times with different `test`s, walk it once
without a test, and use [`unist-util-is`][is] to check if a node matches a test,
and then perform different operations.
###### Parameters
* `tree` ([`Node`][node]) — [Tree][] to traverse
* `test` ([`Test`][is], optional) — [`is`][is]-compatible test (such as a
[type][])
* `visitor` ([Function][visitor]) — Function invoked when a node is found
that passes `test`
* `reverse` (`boolean`, default: `false`) — The tree is traversed in
[preorder][] (NLR), visiting the node itself, then its [head][], etc.
When `reverse` is passed, the tree is traversed in reverse preorder (NRL):
the node itself is visited, then its [tail][], etc.
#### `next? = visitor(node, ancestors)`
Invoked when a node (matching `test`, if given) is found.
Visitors are free to transform `node`.
They can also transform the [parent][] of node (the last of `ancestors`).
Replacing `node` itself, if `visit.SKIP` is not returned, still causes its
[descendant][]s to be visited.
If adding or removing previous [sibling][]s (or next siblings, in case of
`reverse`) of `node`, `visitor` should return a new [`index`][index] (`number`)
to specify the sibling to traverse after `node` is traversed.
Adding or removing next siblings of `node` (or previous siblings, in case of
reverse) is handled as expected without needing to return a new `index`.
Removing the `children` property of an ancestor still results in them being
traversed.
###### Parameters
* `node` ([`Node`][node]) — Found node
* `ancestors` (`Array.<Node>`) — [Ancestor][]s of `node`
##### Returns
The return value can have the following forms:
* [`index`][index] (`number`) — Treated as a tuple of `[CONTINUE, index]`
* `action` (`*`) — Treated as a tuple of `[action]`
* `tuple` (`Array.<*>`) — List with one or two values, the first an `action`,
the second and `index`.
Note that passing a tuple only makes sense if the `action` is `SKIP`.
If the `action` is `EXIT`, that action can be returned.
If the `action` is `CONTINUE`, `index` can be returned.
###### `action`
An action can have the following values:
* `visit.EXIT` (`false`) — Stop traversing immediately
* `visit.CONTINUE` (`true`) — Continue traversing as normal (same behaviour
as not returning anything)
* `visit.SKIP` (`'skip'`) — Do not traverse this nodes children; continue
with the specified index
###### `index`
[`index`][index] (`number`) — Move to the sibling at `index` next (after `node`
itself is completely traversed).
Useful if mutating the tree, such as removing the node the visitor is currently
on, or any of its previous siblings (or next siblings, in case of `reverse`)
Results less than `0` or greater than or equal to `children.length` stop
traversing the parent
## Related
* [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit)
— Like `visit-parents`, but with one parent
* [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)
— Create a new tree with all nodes that pass a test
* [`unist-util-map`](https://github.com/syntax-tree/unist-util-map)
— Create a new tree with all nodes mapped by a given function
* [`unist-util-flatmap`](https://gitlab.com/staltz/unist-util-flatmap)
— Create a new tree by mapping (to an array) with the given function
* [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)
— Remove nodes from a tree that pass a test
* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)
— Select nodes with CSS-like selectors
## 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]
<!-- Definition -->
[build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-visit-parents.svg
[build]: https://travis-ci.org/syntax-tree/unist-util-visit-parents
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-visit-parents.svg
[coverage]: https://codecov.io/github/syntax-tree/unist-util-visit-parents
[downloads-badge]: https://img.shields.io/npm/dm/unist-util-visit-parents.svg
[downloads]: https://www.npmjs.com/package/unist-util-visit-parents
[size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-visit-parents.svg
[size]: https://bundlephobia.com/result?p=unist-util-visit-parents
[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
[unist]: https://github.com/syntax-tree/unist
[node]: https://github.com/syntax-tree/unist#node
[visitor]: #next--visitornode-ancestors
[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
[is]: https://github.com/syntax-tree/unist-util-is
[depth-first]: https://github.com/syntax-tree/unist#depth-first-traversal
[tree-traversal]: https://github.com/syntax-tree/unist#tree-traversal
[preorder]: https://github.com/syntax-tree/unist#preorder
[descendant]: https://github.com/syntax-tree/unist#descendant
[head]: https://github.com/syntax-tree/unist#head
[tail]: https://github.com/syntax-tree/unist#tail
[parent]: https://github.com/syntax-tree/unist#parent-1
[sibling]: https://github.com/syntax-tree/unist#sibling
[index]: https://github.com/syntax-tree/unist#index
[ancestor]: https://github.com/syntax-tree/unist#ancestor
[tree]: https://github.com/syntax-tree/unist#tree
[type]: https://github.com/syntax-tree/unist#type

View File

@@ -0,0 +1,111 @@
// TypeScript Version: 3.5
import {Node, Parent} from 'unist'
import {Test} from 'unist-util-is'
declare namespace visitParents {
/**
* Continue traversing as normal
*/
type Continue = true
/**
* Do not traverse this nodes children
*/
type Skip = 'skip'
/**
* Stop traversing immediately
*/
type Exit = false
/**
* Union of the action types
*/
type Action = Continue | Skip | Exit
/**
* List with one or two values, the first an action, the second an index.
*/
type ActionTuple = [Action, Index]
/**
* Move to the sibling at index next (after node itself is completely traversed).
* Useful if mutating the tree, such as removing the node the visitor is currently on,
* or any of its previous siblings (or next siblings, in case of reverse)
* Results less than 0 or greater than or equal to children.length stop traversing the parent
*/
type Index = number
/**
* Invoked when a node (matching test, if given) is found.
* Visitors are free to transform node.
* They can also transform the parent of node (the last of ancestors).
* Replacing node itself, if visit.SKIP is not returned, still causes its descendants to be visited.
* If adding or removing previous siblings (or next siblings, in case of reverse) of node,
* visitor should return a new index (number) to specify the sibling to traverse after node is traversed.
* Adding or removing next siblings of node (or previous siblings, in case of reverse)
* is handled as expected without needing to return a new index.
* Removing the children property of an ancestor still results in them being traversed.
*
* @param node Found node
* @param ancestors Ancestors of node
* @paramType V node type found
* @returns
* When Action is passed, treated as a tuple of [Action]
* When Index is passed, treated as a tuple of [CONTINUE, Index]
* When ActionTuple is passed,
* Note that passing a tuple only makes sense if the action is SKIP.
* If the action is EXIT, that action can be returned.
* If the action is CONTINUE, index can be returned.
*/
type Visitor<V extends Node> = (
node: V,
ancestors: Node[]
) => void | Action | Index | ActionTuple
}
declare const visitParents: {
/**
* Visit children of tree which pass a test
*
* @param tree abstract syntax tree to visit
* @param test test node
* @param visitor function to run for each node
* @param reverse visit the tree in reverse, defaults to false
* @typeParam T tree node
* @typeParam V node type found
*/
<V extends Node>(
tree: Node,
test: Test<V> | Array<Test<any>>,
visitor: visitParents.Visitor<V>,
reverse?: boolean
): void
/**
* Visit children of a tree
*
* @param tree abstract syntax tree to visit
* @param visitor function to run for each node
* @param reverse visit the tree in reverse, defaults to false
*/
(tree: Node, visitor: visitParents.Visitor<Node>, reverse?: boolean): void
/**
* Continue traversing as normal
*/
CONTINUE: visitParents.Continue
/**
* Do not traverse this nodes children
*/
SKIP: visitParents.Skip
/**
* Stop traversing immediately
*/
EXIT: visitParents.Exit
}
export = visitParents

View File

@@ -0,0 +1,29 @@
'use strict'
module.exports = visit
var visitParents = require('unist-util-visit-parents')
var CONTINUE = visitParents.CONTINUE
var SKIP = visitParents.SKIP
var EXIT = visitParents.EXIT
visit.CONTINUE = CONTINUE
visit.SKIP = SKIP
visit.EXIT = EXIT
function visit(tree, test, visitor, reverse) {
if (typeof test === 'function' && typeof visitor !== 'function') {
reverse = visitor
visitor = test
test = null
}
visitParents(tree, test, overload, reverse)
function overload(node, parents) {
var parent = parents[parents.length - 1]
var index = parent ? parent.children.indexOf(node) : null
return visitor(node, index, parent)
}
}

View File

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

View File

@@ -0,0 +1,105 @@
{
"name": "unist-util-visit",
"version": "2.0.3",
"description": "unist utility to visit nodes",
"license": "MIT",
"keywords": [
"unist",
"unist-util",
"util",
"utility",
"remark",
"retext",
"rehype",
"mdast",
"hast",
"xast",
"nlcst",
"natural",
"language",
"markdown",
"html",
"xml",
"tree",
"ast",
"node",
"visit",
"walk"
],
"repository": "syntax-tree/unist-util-visit",
"bugs": "https://github.com/syntax-tree/unist-util-visit/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)",
"Eugene Sharygin <eush77@gmail.com>",
"Richard Gibson <richard.gibson@gmail.com>"
],
"files": [
"index.js",
"types/index.d.ts"
],
"types": "types/index.d.ts",
"dependencies": {
"@types/unist": "^2.0.0",
"unist-util-is": "^4.0.0",
"unist-util-visit-parents": "^3.0.0"
},
"devDependencies": {
"browserify": "^16.0.0",
"dtslint": "^3.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark": "^12.0.0",
"remark-cli": "^8.0.0",
"remark-preset-wooorm": "^7.0.0",
"tape": "^5.0.0",
"tinyify": "^2.0.0",
"typescript": "^3.0.0",
"unified": "^9.0.0",
"xo": "^0.32.0"
},
"scripts": {
"format": "remark . -qfo && prettier . --write && xo --fix",
"build-bundle": "browserify . -s unistUtilVisit > unist-util-visit.js",
"build-mangle": "browserify . -s unistUtilVisit -p tinyify > unist-util-visit.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test-types": "dtslint types",
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
},
"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,
"rules": {
"unicorn/prefer-set-has": "off"
},
"ignores": [
"unist-util-visit.js",
"types"
]
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
}
}

View File

@@ -0,0 +1,136 @@
# unist-util-visit
[![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]
[**unist**][unist] utility to visit nodes.
## Install
[npm][]:
```sh
npm install unist-util-visit
```
## Use
```js
var u = require('unist-builder')
var visit = require('unist-util-visit')
var tree = u('tree', [
u('leaf', '1'),
u('node', [u('leaf', '2')]),
u('void'),
u('leaf', '3')
])
visit(tree, 'leaf', function(node) {
console.log(node)
})
```
Yields:
```js
{ type: 'leaf', value: '1' }
{ type: 'leaf', value: '2' }
{ type: 'leaf', value: '3' }
```
## API
### `visit(tree[, test], visitor[, reverse])`
This function works exactly the same as [`unist-util-visit-parents`][vp],
but `visitor` has a different signature.
#### `next? = visitor(node, index, parent)`
Instead of being passed an array of ancestors, `visitor` is invoked with the
nodes [`index`][index] and its [`parent`][parent].
Otherwise the same as [`unist-util-visit-parents`][vp].
## Related
* [`unist-util-visit-parents`][vp]
— Like `visit`, but with a stack of parents
* [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)
— Create a new tree with all nodes that pass a test
* [`unist-util-map`](https://github.com/syntax-tree/unist-util-map)
— Create a new tree with all nodes mapped by a given function
* [`unist-util-flatmap`](https://gitlab.com/staltz/unist-util-flatmap)
— Create a new tree by mapping (to an array) with the given function
* [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)
— Remove nodes from a tree that pass a test
* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)
— Select nodes with CSS-like selectors
## 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]
<!-- Definition -->
[build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-visit.svg
[build]: https://travis-ci.org/syntax-tree/unist-util-visit
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-visit.svg
[coverage]: https://codecov.io/github/syntax-tree/unist-util-visit
[downloads-badge]: https://img.shields.io/npm/dm/unist-util-visit.svg
[downloads]: https://www.npmjs.com/package/unist-util-visit
[size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-visit.svg
[size]: https://bundlephobia.com/result?p=unist-util-visit
[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-spectrum-7b16ff.svg
[chat]: https://spectrum.chat/unified/syntax-tree
[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
[unist]: https://github.com/syntax-tree/unist
[vp]: https://github.com/syntax-tree/unist-util-visit-parents
[index]: https://github.com/syntax-tree/unist#index
[parent]: https://github.com/syntax-tree/unist#parent-1

View File

@@ -0,0 +1,88 @@
// TypeScript Version: 3.5
import {Node, Parent} from 'unist'
import {Test} from 'unist-util-is'
import {
Action,
ActionTuple,
Continue,
Exit,
Index,
Skip
} from 'unist-util-visit-parents'
declare namespace visit {
/**
* Invoked when a node (matching test, if given) is found.
* Visitors are free to transform node.
* They can also transform the parent of node.
* Replacing node itself, if visit.SKIP is not returned, still causes its descendants to be visited.
* If adding or removing previous siblings (or next siblings, in case of reverse) of node,
* visitor should return a new index (number) to specify the sibling to traverse after node is traversed.
* Adding or removing next siblings of node (or previous siblings, in case of reverse)
* is handled as expected without needing to return a new index.
* Removing the children property of the parent still result in them being traversed.
*
* @param node Found node
* @param index Position of found node within Parent
* @param parent Parent of found node
* @paramType V node type found
* @returns
* When Action is passed, treated as a tuple of [Action]
* When Index is passed, treated as a tuple of [CONTINUE, Index]
* When ActionTuple is passed,
* Note that passing a tuple only makes sense if the action is SKIP.
* If the action is EXIT, that action can be returned.
* If the action is CONTINUE, index can be returned.
*/
type Visitor<V extends Node> = (
node: V,
index: number,
parent: Parent | undefined
) => void | Action | Index | ActionTuple
}
declare const visit: {
/**
* Visit children of tree which pass a test
*
* @param tree abstract syntax tree to visit
* @param test test node
* @param visitor function to run for each node
* @param reverse visit the tree in reverse, defaults to false
* @typeParam T tree node
* @typeParam V node type found
*/
<V extends Node>(
tree: Node,
test: Test<V> | Array<Test<any>>,
visitor: visit.Visitor<V>,
reverse?: boolean
): void
/**
* Visit children of a tree
*
* @param tree abstract syntax tree to visit
* @param visitor function to run for each node
* @param reverse visit the tree in reverse, defaults to false
*/
(tree: Node, visitor: visit.Visitor<Node>, reverse?: boolean): void
/**
* Continue traversing as normal
*/
CONTINUE: Continue
/**
* Do not traverse this nodes children
*/
SKIP: Skip
/**
* Stop traversing immediately
*/
EXIT: Exit
}
export = visit

104
node_modules/hast-util-to-mdast/package.json generated vendored Normal file
View File

@@ -0,0 +1,104 @@
{
"name": "hast-util-to-mdast",
"version": "7.1.3",
"description": "hast utility to transform to mdast",
"license": "MIT",
"keywords": [
"unist",
"hast",
"hast-util",
"mdast",
"mdast-util",
"rehype",
"remark",
"markdown",
"html",
"transform"
],
"repository": "syntax-tree/hast-util-to-mdast",
"bugs": "https://github.com/syntax-tree/hast-util-to-mdast/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Seth Vincent <sethvincent@gmail.com> (https://sethvincent.com)",
"contributors": [
"Seth Vincent <sethvincent@gmail.com> (https://sethvincent.com)",
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"files": [
"index.js",
"lib"
],
"dependencies": {
"extend": "^3.0.0",
"hast-util-has-property": "^1.0.0",
"hast-util-is-element": "^1.1.0",
"hast-util-to-text": "^2.0.0",
"mdast-util-phrasing": "^2.0.0",
"mdast-util-to-string": "^1.0.0",
"rehype-minify-whitespace": "^4.0.3",
"repeat-string": "^1.6.1",
"trim-trailing-lines": "^1.1.0",
"unist-util-is": "^4.0.0",
"unist-util-visit": "^2.0.0",
"xtend": "^4.0.1"
},
"devDependencies": {
"hastscript": "^6.0.0",
"is-hidden": "^1.0.0",
"mdast-util-assert": "^3.0.0",
"negate": "^1.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"rehype-parse": "^7.0.0",
"remark-cli": "^9.0.0",
"remark-gfm": "^1.0.0",
"remark-parse": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"remark-stringify": "^9.0.0",
"tape": "^5.0.0",
"unified": "^9.0.0",
"unist-builder": "^2.0.0",
"unist-util-remove-position": "^3.0.0",
"xo": "^0.34.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test": "npm run format && 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,
"rules": {
"complexity": "off",
"no-multi-assign": "off",
"unicorn/escape-case": "off",
"unicorn/explicit-length-check": "off",
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/prefer-number-properties": "off",
"unicorn/prefer-optional-catch-binding": "off"
}
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
}
}

341
node_modules/hast-util-to-mdast/readme.md generated vendored Normal file
View File

@@ -0,0 +1,341 @@
# hast-util-to-mdast
[![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 transform to [**mdast**][mdast].
> **Note**: You probably want to use [rehype-remark][].
## Install
[npm][]:
```sh
npm install hast-util-to-mdast
```
## Use
Say we have the following `example.html`:
```html
<h2>Hello <strong>world!</strong></h2>
```
…and next to it, `example.js`:
```js
var unified = require('unified')
var parse = require('rehype-parse')
var stringify = require('remark-stringify')
var vfile = require('to-vfile')
var toMdast = require('hast-util-to-mdast')
var file = vfile.readSync('example.html')
var hast = unified()
.use(parse)
.parse(file)
var mdast = toMdast(hast)
var doc = unified()
.use(stringify)
.stringify(mdast)
console.log(doc)
```
Now, running `node example.js` yields:
```markdown
## Hello **world!**
```
## API
### `toMdast(tree[, options])`
Transform the given [**hast**][hast] [*tree*][tree] to [**mdast**][mdast].
##### Options
###### `options.handlers`
Object mapping tag names or [*types*][type] to functions handling those
[*elements*][element] or [*nodes*][hast-node].
See [`handlers/`][handlers] for examples.
In a handler, you have access to `h`, which should be used to create mdast nodes
from hast nodes.
On `h`, there are fields that may be of interest.
Most interesting of them is `h.wrapText`, which is `true` if the mdast content
can include newlines, and `false` if not (such as in headings or table cells).
###### `options.document`
Whether the given [*tree*][tree] is a complete document.
Applies if the given `tree` is a [`root`][hast-root].
First its [*children*][child] are transformed to [**mdast**][mdast].
By default, if one or more of the new mdast children are [*phrasing*][phrasing]
nodes, and one or more are not, the phrasing nodes are wrapped in
[*paragraphs*][mdast-paragraph].
If `document: true`, all mdast phrasing children are wrapped in paragraphs.
###### `options.newlines`
Whether to collapse to a line feed (`\n`) instead of a single space (default) if
a streak of white-space in a text node contains a newline.
###### `options.checked`
Value to use when serializing a checked checkbox or radio input (`string`,
default: `[x]`).
###### `options.unchecked`
Value to use when serializing an unchecked checkbox or radio input (`string`,
default: `[ ]`).
###### `options.quotes`
List of quotes to use (`string[]`, default: `['"']`).
Each value can be one or two characters.
When two, the first character determines the opening quote and the second the
closing quote at that level.
When one, both the opening and closing quote are that character.
The order in which the preferred quotes appear determines which quotes to use at
which level of nesting.
So, to prefer `` at the first level of nesting, and `“”` at the second, pass:
`['', '“”']`.
If `<q>`s are nested deeper than the given amount of quotes, the markers wrap
around: a third level of nesting when using `['«»', '']` should have double
guillemets, a fourth single, a fifth double again, etc.
##### Returns
[`MdastNode`][mdast-node].
##### Notes
###### Implied paragraphs
The algorithm supports implicit and explicit paragraphs (see [HTML Standard,
A. van Kesteren; et al. WHATWG § 3.2.5.4 Paragraphs][spec]), such as:
```html
<article>
An implicit paragraph.
<h1>An explicit paragraph.</h1>
</article>
```
Yields:
```markdown
An implicit paragraph.
# An explicit paragraph.
```
###### Ignoring nodes
Some [*nodes*][hast-node] are ignored and their content will not be present in
the [**mdast**][mdast] [*tree*][tree].
To ignore nodes, configure a [handler][] for their tag name or [*type*][type]
that returns nothing.
For example, to ignore `em` [*elements*][element], pass `handlers: {'em':
function () {}}`:
```html
<p><strong>Importance</strong> and <em>emphasis</em>.</p>
```
Yields:
```markdown
**Importance** and .
```
To ignore a specific element from the HTML source, set `data-mdast` to
`ignore`:
```html
<p><strong>Importance</strong> and <em data-mdast="ignore">emphasis</em>.</p>
```
Yields:
```markdown
**Importance** and .
```
###### HTML in Markdown
We try our best to map any HTML (hast) to Markdown (mdast) and keep it readable.
Readability is one of Markdowns greatest features: its terser than HTML, such
as allowing `# Alpha` instead of `<h1>Alpha</h1>`.
Another awesome feature of Markdown is that you *can* author HTML inside it.
As we focus on readability we dont do that, but you can by passing a handler.
Say we for example have this HTML, and want to embed the SVG inside Markdown as
well:
```html
<p>
Some text with
<svg viewBox="0 0 1 1" width="1" height="1"><rect fill="black" x="0" y="0" width="1" height="1" /></svg>
a graphic… Wait is that a dead pixel?
</p>
```
This can be achieved with `example.js` like so:
```js
var unified = require('unified')
var parse = require('rehype-parse')
var stringify = require('remark-stringify')
var vfile = require('to-vfile')
var toHtml = require('hast-util-to-html')
var toMdast = require('hast-util-to-mdast')
var file = vfile.readSync('example.html')
var hast = unified()
.use(parse)
.parse(file)
var mdast = toMdast(hast, {handlers: {svg: svg}})
var doc = unified()
.use(stringify)
.stringify(mdast)
console.log(doc)
function svg(h, node) {
return h(node, 'html', toHtml(node, {space: 'svg'}))
}
```
Yields:
```markdown
Some text with <svg viewBox="0 0 1 1" width="1" height="1"><rect fill="black" x="0" y="0" width="1" height="1"></rect></svg> a graphic… Wait is that a dead pixel?
```
## Security
Use of `hast-util-to-mdast` can open you up to a
[cross-site scripting (XSS)][xss] attack if the hast tree is unsafe.
Use [`hast-util-santize`][sanitize] to make the hast tree safe.
## Related
* [`hast-util-to-nlcst`](https://github.com/syntax-tree/hast-util-to-nlcst)
— transform hast to nlcst
* [`hast-util-to-xast`](https://github.com/syntax-tree/hast-util-to-xast)
— transform hast to xast
* [`mdast-util-to-hast`](https://github.com/syntax-tree/mdast-util-to-hast)
— transform mdast to hast
* [`mdast-util-to-nlcst`](https://github.com/syntax-tree/mdast-util-to-nlcst)
— transform mdast to nlcst
* [`remark-rehype`](https://github.com/remarkjs/remark-rehype)
— rehype support for remark
* [`rehype-remark`](https://github.com/rehypejs/rehype-remark)
— remark support for rehype
## 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://github.com/syntax-tree/hast-util-to-mdast/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/hast-util-to-mdast/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-mdast.svg
[coverage]: https://codecov.io/github/syntax-tree/hast-util-to-mdast
[downloads-badge]: https://img.shields.io/npm/dm/hast-util-to-mdast.svg
[downloads]: https://www.npmjs.com/package/hast-util-to-mdast
[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-to-mdast.svg
[size]: https://bundlephobia.com/result?p=hast-util-to-mdast
[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
[tree]: https://github.com/syntax-tree/unist#tree
[child]: https://github.com/syntax-tree/unist#child
[type]: https://github.com/syntax-tree/unist#type
[mdast]: https://github.com/syntax-tree/mdast
[mdast-paragraph]: https://github.com/syntax-tree/mdast#paragraph
[mdast-node]: https://github.com/syntax-tree/mdast#nodes
[phrasing]: https://github.com/syntax-tree/mdast#phrasingcontent
[hast]: https://github.com/syntax-tree/hast
[hast-node]: https://github.com/syntax-tree/hast#nodes
[hast-root]: https://github.com/syntax-tree/hast#root
[element]: https://github.com/syntax-tree/hast#element
[rehype-remark]: https://github.com/rehypejs/rehype-remark
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[sanitize]: https://github.com/syntax-tree/hast-util-sanitize
[handler]: #optionshandlers
[handlers]: https://github.com/syntax-tree/hast-util-to-mdast/tree/main/lib/handlers
[spec]: https://html.spec.whatwg.org/#paragraphs