Files
react-native-devtools-frontend/node_modules/remark-stringify/lib/macro/block.js
T
Mathias Bynens 79e2cf0633 Add stylelint dependency
This also adds CC-BY-4.0 to the list of accepted licenses.

DISABLE_THIRD_PARTY_CHECK=update dependencies

Bug: chromium:1083142
Change-Id: I8612de2fba52dae32eeb71af79d5aacfde52142b
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2220097
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
2020-06-11 06:20:04 +00:00

55 lines
1.5 KiB
JavaScript

'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 previous
var child
while (++index < length) {
previous = child
child = children[index]
if (previous) {
// 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 (
previous.type === 'list' &&
((child.type === 'list' && previous.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('')
}