3 var repeat = require('repeat-string');
5 module.exports = heading;
7 /* Stringify a heading.
9 * In `setext: true` mode and when `depth` is smaller than
10 * three, creates a setext header:
15 * Otherwise, an ATX header is generated:
19 * In `closeAtx: true` mode, the header is closed with
24 function heading(node) {
26 var depth = node.depth;
27 var setext = self.options.setext;
28 var closeAtx = self.options.closeAtx;
29 var content = self.all(node).join('');
32 if (setext && depth < 3) {
33 return content + '\n' + repeat(depth === 1 ? '=' : '-', content.length);
36 prefix = repeat('#', node.depth);
38 return prefix + ' ' + content + (closeAtx ? ' ' + prefix : '');