This commit is contained in:
168
node_modules/hast-util-to-html/lib/omission/closing.js
generated
vendored
Normal file
168
node_modules/hast-util-to-html/lib/omission/closing.js
generated
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
'use strict'
|
||||
|
||||
var element = require('hast-util-is-element')
|
||||
var whiteSpaceStart = require('./util/white-space-start')
|
||||
var comment = require('./util/comment')
|
||||
var siblings = require('./util/siblings')
|
||||
var omission = require('./omission')
|
||||
|
||||
module.exports = omission({
|
||||
html: html,
|
||||
head: headOrColgroupOrCaption,
|
||||
body: body,
|
||||
p: p,
|
||||
li: li,
|
||||
dt: dt,
|
||||
dd: dd,
|
||||
rt: rubyElement,
|
||||
rp: rubyElement,
|
||||
optgroup: optgroup,
|
||||
option: option,
|
||||
menuitem: menuitem,
|
||||
colgroup: headOrColgroupOrCaption,
|
||||
caption: headOrColgroupOrCaption,
|
||||
thead: thead,
|
||||
tbody: tbody,
|
||||
tfoot: tfoot,
|
||||
tr: tr,
|
||||
td: cells,
|
||||
th: cells
|
||||
})
|
||||
|
||||
// Macro for `</head>`, `</colgroup>`, and `</caption>`.
|
||||
function headOrColgroupOrCaption(node, index, parent) {
|
||||
var next = siblings.after(parent, index, true)
|
||||
return !next || (!comment(next) && !whiteSpaceStart(next))
|
||||
}
|
||||
|
||||
// Whether to omit `</html>`.
|
||||
function html(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || !comment(next)
|
||||
}
|
||||
|
||||
// Whether to omit `</body>`.
|
||||
function body(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || !comment(next)
|
||||
}
|
||||
|
||||
// Whether to omit `</p>`.
|
||||
function p(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return next
|
||||
? element(next, [
|
||||
'address',
|
||||
'article',
|
||||
'aside',
|
||||
'blockquote',
|
||||
'details',
|
||||
'div',
|
||||
'dl',
|
||||
'fieldset',
|
||||
'figcaption',
|
||||
'figure',
|
||||
'footer',
|
||||
'form',
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
'h4',
|
||||
'h5',
|
||||
'h6',
|
||||
'header',
|
||||
'hgroup',
|
||||
'hr',
|
||||
'main',
|
||||
'menu',
|
||||
'nav',
|
||||
'ol',
|
||||
'p',
|
||||
'pre',
|
||||
'section',
|
||||
'table',
|
||||
'ul'
|
||||
])
|
||||
: !parent ||
|
||||
// Confusing parent.
|
||||
!element(parent, [
|
||||
'a',
|
||||
'audio',
|
||||
'del',
|
||||
'ins',
|
||||
'map',
|
||||
'noscript',
|
||||
'video'
|
||||
])
|
||||
}
|
||||
|
||||
// Whether to omit `</li>`.
|
||||
function li(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || element(next, 'li')
|
||||
}
|
||||
|
||||
// Whether to omit `</dt>`.
|
||||
function dt(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return next && element(next, ['dt', 'dd'])
|
||||
}
|
||||
|
||||
// Whether to omit `</dd>`.
|
||||
function dd(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || element(next, ['dt', 'dd'])
|
||||
}
|
||||
|
||||
// Whether to omit `</rt>` or `</rp>`.
|
||||
function rubyElement(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || element(next, ['rp', 'rt'])
|
||||
}
|
||||
|
||||
// Whether to omit `</optgroup>`.
|
||||
function optgroup(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || element(next, 'optgroup')
|
||||
}
|
||||
|
||||
// Whether to omit `</option>`.
|
||||
function option(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || element(next, ['option', 'optgroup'])
|
||||
}
|
||||
|
||||
// Whether to omit `</menuitem>`.
|
||||
function menuitem(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || element(next, ['menuitem', 'hr', 'menu'])
|
||||
}
|
||||
|
||||
// Whether to omit `</thead>`.
|
||||
function thead(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return next && element(next, ['tbody', 'tfoot'])
|
||||
}
|
||||
|
||||
// Whether to omit `</tbody>`.
|
||||
function tbody(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || element(next, ['tbody', 'tfoot'])
|
||||
}
|
||||
|
||||
// Whether to omit `</tfoot>`.
|
||||
function tfoot(node, index, parent) {
|
||||
return !siblings.after(parent, index)
|
||||
}
|
||||
|
||||
// Whether to omit `</tr>`.
|
||||
function tr(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || element(next, 'tr')
|
||||
}
|
||||
|
||||
// Whether to omit `</td>` or `</th>`.
|
||||
function cells(node, index, parent) {
|
||||
var next = siblings.after(parent, index)
|
||||
return !next || element(next, ['td', 'th'])
|
||||
}
|
||||
3
node_modules/hast-util-to-html/lib/omission/index.js
generated
vendored
Normal file
3
node_modules/hast-util-to-html/lib/omission/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict'
|
||||
exports.opening = require('./opening')
|
||||
exports.closing = require('./closing')
|
||||
18
node_modules/hast-util-to-html/lib/omission/omission.js
generated
vendored
Normal file
18
node_modules/hast-util-to-html/lib/omission/omission.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = omission
|
||||
|
||||
var own = {}.hasOwnProperty
|
||||
|
||||
// Factory to check if a given node can have a tag omitted.
|
||||
function omission(handlers) {
|
||||
return omit
|
||||
|
||||
// Check if a given node can have a tag omitted.
|
||||
function omit(node, index, parent) {
|
||||
return (
|
||||
own.call(handlers, node.tagName) &&
|
||||
handlers[node.tagName](node, index, parent)
|
||||
)
|
||||
}
|
||||
}
|
||||
85
node_modules/hast-util-to-html/lib/omission/opening.js
generated
vendored
Normal file
85
node_modules/hast-util-to-html/lib/omission/opening.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
'use strict'
|
||||
|
||||
var element = require('hast-util-is-element')
|
||||
var siblings = require('./util/siblings')
|
||||
var whiteSpaceStart = require('./util/white-space-start')
|
||||
var comment = require('./util/comment')
|
||||
var closing = require('./closing')
|
||||
var omission = require('./omission')
|
||||
|
||||
module.exports = omission({
|
||||
html: html,
|
||||
head: head,
|
||||
body: body,
|
||||
colgroup: colgroup,
|
||||
tbody: tbody
|
||||
})
|
||||
|
||||
// Whether to omit `<html>`.
|
||||
function html(node) {
|
||||
var head = siblings.after(node, -1)
|
||||
return !head || !comment(head)
|
||||
}
|
||||
|
||||
// Whether to omit `<head>`.
|
||||
function head(node) {
|
||||
var children = node.children
|
||||
var seen = []
|
||||
var index = -1
|
||||
|
||||
while (++index < children.length) {
|
||||
if (element(children[index], ['title', 'base'])) {
|
||||
if (seen.indexOf(children[index].tagName) > -1) return false
|
||||
seen.push(children[index].tagName)
|
||||
}
|
||||
}
|
||||
|
||||
return children.length
|
||||
}
|
||||
|
||||
// Whether to omit `<body>`.
|
||||
function body(node) {
|
||||
var head = siblings.after(node, -1, true)
|
||||
|
||||
return (
|
||||
!head ||
|
||||
(!comment(head) &&
|
||||
!whiteSpaceStart(head) &&
|
||||
!element(head, ['meta', 'link', 'script', 'style', 'template']))
|
||||
)
|
||||
}
|
||||
|
||||
// Whether to omit `<colgroup>`.
|
||||
// The spec describes some logic for the opening tag, but it’s easier to
|
||||
// implement in the closing tag, to the same effect, so we handle it there
|
||||
// instead.
|
||||
function colgroup(node, index, parent) {
|
||||
var previous = siblings.before(parent, index)
|
||||
var head = siblings.after(node, -1, true)
|
||||
|
||||
// Previous colgroup was already omitted.
|
||||
if (
|
||||
element(previous, 'colgroup') &&
|
||||
closing(previous, parent.children.indexOf(previous), parent)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
return head && element(head, 'col')
|
||||
}
|
||||
|
||||
// Whether to omit `<tbody>`.
|
||||
function tbody(node, index, parent) {
|
||||
var previous = siblings.before(parent, index)
|
||||
var head = siblings.after(node, -1)
|
||||
|
||||
// Previous table section was already omitted.
|
||||
if (
|
||||
element(previous, ['thead', 'tbody']) &&
|
||||
closing(previous, parent.children.indexOf(previous), parent)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
return head && element(head, 'tr')
|
||||
}
|
||||
5
node_modules/hast-util-to-html/lib/omission/util/comment.js
generated
vendored
Normal file
5
node_modules/hast-util-to-html/lib/omission/util/comment.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
var convert = require('unist-util-is/convert')
|
||||
|
||||
module.exports = convert('comment')
|
||||
27
node_modules/hast-util-to-html/lib/omission/util/siblings.js
generated
vendored
Normal file
27
node_modules/hast-util-to-html/lib/omission/util/siblings.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict'
|
||||
|
||||
var whiteSpace = require('hast-util-whitespace')
|
||||
|
||||
exports.before = siblings(-1)
|
||||
exports.after = siblings(1)
|
||||
|
||||
// Factory to check siblings in a direction.
|
||||
function siblings(increment) {
|
||||
return sibling
|
||||
|
||||
// Find applicable siblings in a direction.
|
||||
function sibling(parent, index, includeWhiteSpace) {
|
||||
var siblings = parent && parent.children
|
||||
var offset = index + increment
|
||||
var next = siblings && siblings[offset]
|
||||
|
||||
if (!includeWhiteSpace) {
|
||||
while (next && whiteSpace(next)) {
|
||||
offset += increment
|
||||
next = siblings[offset]
|
||||
}
|
||||
}
|
||||
|
||||
return next
|
||||
}
|
||||
}
|
||||
13
node_modules/hast-util-to-html/lib/omission/util/white-space-start.js
generated
vendored
Normal file
13
node_modules/hast-util-to-html/lib/omission/util/white-space-start.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
var convert = require('unist-util-is/convert')
|
||||
var whiteSpace = require('hast-util-whitespace')
|
||||
|
||||
module.exports = whiteSpaceStart
|
||||
|
||||
var isText = convert('text')
|
||||
|
||||
// Check if `node` starts with white-space.
|
||||
function whiteSpaceStart(node) {
|
||||
return isText(node) && whiteSpace(node.value.charAt(0))
|
||||
}
|
||||
Reference in New Issue
Block a user