.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-stringify / lib / visitors / table.js
1 'use strict';
2
3 var markdownTable = require('markdown-table');
4
5 module.exports = table;
6
7 /* Stringify table.
8  *
9  * Creates a fenced table by default, but not in
10  * `looseTable: true` mode:
11  *
12  *     Foo | Bar
13  *     :-: | ---
14  *     Baz | Qux
15  *
16  * NOTE: Be careful with `looseTable: true` mode, as a
17  * loose table inside an indented code block on GitHub
18  * renders as an actual table!
19  *
20  * Creates a spaced table by default, but not in
21  * `spacedTable: false`:
22  *
23  *     |Foo|Bar|
24  *     |:-:|---|
25  *     |Baz|Qux|
26  */
27 function table(node) {
28   var self = this;
29   var options = self.options;
30   var loose = options.looseTable;
31   var spaced = options.spacedTable;
32   var pad = options.paddedTable;
33   var stringLength = options.stringLength;
34   var rows = node.children;
35   var index = rows.length;
36   var exit = self.enterTable();
37   var result = [];
38   var start;
39   var end;
40
41   while (index--) {
42     result[index] = self.all(rows[index]);
43   }
44
45   exit();
46
47   if (loose) {
48     start = '';
49     end = '';
50   } else if (spaced) {
51     start = '| ';
52     end = ' |';
53   } else {
54     start = '|';
55     end = '|';
56   }
57
58   return markdownTable(result, {
59     align: node.align,
60     pad: pad,
61     start: start,
62     end: end,
63     stringLength: stringLength,
64     delimiter: spaced ? ' | ' : '|'
65   });
66 }