diff options
Diffstat (limited to 'assets/node_modules/remark-stringify/lib/macro/block.js')
-rw-r--r-- | assets/node_modules/remark-stringify/lib/macro/block.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/assets/node_modules/remark-stringify/lib/macro/block.js b/assets/node_modules/remark-stringify/lib/macro/block.js new file mode 100644 index 0000000..ede130e --- /dev/null +++ b/assets/node_modules/remark-stringify/lib/macro/block.js @@ -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('') +} |