.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-stringify / lib / macro / block.js
1 'use strict';
2
3 module.exports = block;
4
5 /* Stringify a block node with block children (e.g., `root`
6  * or `blockquote`).
7  * Knows about code following a list, or adjacent lists
8  * with similar bullets, and places an extra newline
9  * between them. */
10 function block(node) {
11   var self = this;
12   var values = [];
13   var children = node.children;
14   var length = children.length;
15   var index = -1;
16   var child;
17   var prev;
18
19   while (++index < length) {
20     child = children[index];
21
22     if (prev) {
23       /* Duplicate nodes, such as a list
24        * directly following another list,
25        * often need multiple new lines.
26        *
27        * Additionally, code blocks following a list
28        * might easily be mistaken for a paragraph
29        * in the list itself. */
30       if (child.type === prev.type && prev.type === 'list') {
31         values.push(prev.ordered === child.ordered ? '\n\n\n' : '\n\n');
32       } else if (prev.type === 'list' && child.type === 'code' && !child.lang) {
33         values.push('\n\n\n');
34       } else {
35         values.push('\n\n');
36       }
37     }
38
39     values.push(self.visit(child, node));
40
41     prev = child;
42   }
43
44   return values.join('');
45 }