This commit is contained in:
66
node_modules/hast-util-to-mdast/lib/util/find-selected-options.js
generated
vendored
Normal file
66
node_modules/hast-util-to-mdast/lib/util/find-selected-options.js
generated
vendored
Normal 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
|
||||
}
|
||||
17
node_modules/hast-util-to-mdast/lib/util/list-items-spread.js
generated
vendored
Normal file
17
node_modules/hast-util-to-mdast/lib/util/list-items-spread.js
generated
vendored
Normal 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
3
node_modules/hast-util-to-mdast/lib/util/own.js
generated
vendored
Normal 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
16
node_modules/hast-util-to-mdast/lib/util/resolve.js
generated
vendored
Normal 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
19
node_modules/hast-util-to-mdast/lib/util/shallow.js
generated
vendored
Normal 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
|
||||
}
|
||||
10
node_modules/hast-util-to-mdast/lib/util/wrap-children.js
generated
vendored
Normal file
10
node_modules/hast-util-to-mdast/lib/util/wrap-children.js
generated
vendored
Normal 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))
|
||||
}
|
||||
23
node_modules/hast-util-to-mdast/lib/util/wrap-list-items.js
generated
vendored
Normal file
23
node_modules/hast-util-to-mdast/lib/util/wrap-list-items.js
generated
vendored
Normal 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
|
||||
}
|
||||
7
node_modules/hast-util-to-mdast/lib/util/wrap-text.js
generated
vendored
Normal file
7
node_modules/hast-util-to-mdast/lib/util/wrap-text.js
generated
vendored
Normal 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
133
node_modules/hast-util-to-mdast/lib/util/wrap.js
generated
vendored
Normal 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 don’t need to worry about that.
|
||||
// `map` maps to its content, so we don’t need to worry about that either.
|
||||
// `del` maps to `delete` and `a` to `link`, so we do handle those.
|
||||
// What we’ll 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
|
||||
// doesn’t 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
|
||||
}
|
||||
Reference in New Issue
Block a user