Sha256: 405fb2a9db0ce9502958f87bf450be32af45061d2af9e3e91ecae9570360870c

Contents?: true

Size: 962 Bytes

Versions: 23

Compression:

Stored size: 962 Bytes

Contents

'use strict'

var repeat = require('repeat-string')

module.exports = heading

var lineFeed = '\n'
var space = ' '
var numberSign = '#'
var dash = '-'
var equalsTo = '='

// Stringify a heading.
//
// In `setext: true` mode and when `depth` is smaller than three, creates a
// setext header:
//
// ```markdown
// Foo
// ===
// ```
//
// Otherwise, an ATX header is generated:
//
// ```markdown
// ### Foo
// ```
//
// In `closeAtx: true` mode, the header is closed with hashes:
//
// ```markdown
// ### Foo ###
// ```
function heading(node) {
  var self = this
  var depth = node.depth
  var setext = self.options.setext
  var closeAtx = self.options.closeAtx
  var content = self.all(node).join('')
  var prefix

  if (setext && depth < 3) {
    return (
      content + lineFeed + repeat(depth === 1 ? equalsTo : dash, content.length)
    )
  }

  prefix = repeat(numberSign, node.depth)

  return prefix + space + content + (closeAtx ? space + prefix : '')
}

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
trusty-cms-5.0.7 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-5.0.6 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-5.0.5 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-5.0.4 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-5.0.3 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-5.0.2 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-5.0.1 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.3.5 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-5.0.0 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.3.4 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.3.3 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.3.2 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.3.1 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.3 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.2.3 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.2.2 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.2.1 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.2 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.1.9 node_modules/remark-stringify/lib/visitors/heading.js
trusty-cms-4.1.8 node_modules/remark-stringify/lib/visitors/heading.js