This commit is contained in:
54
node_modules/remark-stringify/lib/macro/block.js
generated
vendored
Normal file
54
node_modules/remark-stringify/lib/macro/block.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = block
|
||||
|
||||
var lineFeed = '\n'
|
||||
|
||||
var blank = lineFeed + lineFeed
|
||||
var triple = blank + lineFeed
|
||||
var comment = blank + '<!---->' + blank
|
||||
|
||||
// Stringify a block node with block children (e.g., `root` or `blockquote`).
|
||||
// Knows about code following a list, or adjacent lists with similar bullets,
|
||||
// and places an extra line feed between them.
|
||||
function block(node) {
|
||||
var self = this
|
||||
var options = self.options
|
||||
var fences = options.fences
|
||||
var gap = options.commonmark ? comment : triple
|
||||
var values = []
|
||||
var children = node.children
|
||||
var length = children.length
|
||||
var index = -1
|
||||
var prev
|
||||
var child
|
||||
|
||||
while (++index < length) {
|
||||
prev = child
|
||||
child = children[index]
|
||||
|
||||
if (prev) {
|
||||
// A list preceding another list that are equally ordered, or a
|
||||
// list preceding an indented code block, need a gap between them,
|
||||
// so as not to see them as one list, or content of the list,
|
||||
// respectively.
|
||||
//
|
||||
// In commonmark, only something that breaks both up can do that,
|
||||
// so we opt for an empty, invisible comment. In other flavours,
|
||||
// two blank lines are fine.
|
||||
if (
|
||||
prev.type === 'list' &&
|
||||
((child.type === 'list' && prev.ordered === child.ordered) ||
|
||||
(child.type === 'code' && (!child.lang && !fences)))
|
||||
) {
|
||||
values.push(gap)
|
||||
} else {
|
||||
values.push(blank)
|
||||
}
|
||||
}
|
||||
|
||||
values.push(self.visit(child, node))
|
||||
}
|
||||
|
||||
return values.join('')
|
||||
}
|
||||
Reference in New Issue
Block a user