.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-stringify / lib / visitors / heading.js
1 'use strict';
2
3 var repeat = require('repeat-string');
4
5 module.exports = heading;
6
7 /* Stringify a heading.
8  *
9  * In `setext: true` mode and when `depth` is smaller than
10  * three, creates a setext header:
11  *
12  *     Foo
13  *     ===
14  *
15  * Otherwise, an ATX header is generated:
16  *
17  *     ### Foo
18  *
19  * In `closeAtx: true` mode, the header is closed with
20  * hashes:
21  *
22  *     ### Foo ###
23  */
24 function heading(node) {
25   var self = this;
26   var depth = node.depth;
27   var setext = self.options.setext;
28   var closeAtx = self.options.closeAtx;
29   var content = self.all(node).join('');
30   var prefix;
31
32   if (setext && depth < 3) {
33     return content + '\n' + repeat(depth === 1 ? '=' : '-', content.length);
34   }
35
36   prefix = repeat('#', node.depth);
37
38   return prefix + ' ' + content + (closeAtx ? ' ' + prefix : '');
39 }