Sha256: 19ec74680ba0471c0d532acbd37598382dc75dd70eccbb3eb2c6ee480f9b64c6

Contents?: true

Size: 1.75 KB

Versions: 23

Compression:

Stored size: 1.75 KB

Contents

'use strict'

module.exports = setextHeading

var lineFeed = '\n'
var tab = '\t'
var space = ' '
var equalsTo = '='
var dash = '-'

var maxIndent = 3

var equalsToDepth = 1
var dashDepth = 2

function setextHeading(eat, value, silent) {
  var self = this
  var now = eat.now()
  var length = value.length
  var index = -1
  var subvalue = ''
  var content
  var queue
  var character
  var marker
  var depth

  // Eat initial indentation.
  while (++index < length) {
    character = value.charAt(index)

    if (character !== space || index >= maxIndent) {
      index--
      break
    }

    subvalue += character
  }

  // Eat content.
  content = ''
  queue = ''

  while (++index < length) {
    character = value.charAt(index)

    if (character === lineFeed) {
      index--
      break
    }

    if (character === space || character === tab) {
      queue += character
    } else {
      content += queue + character
      queue = ''
    }
  }

  now.column += subvalue.length
  now.offset += subvalue.length
  subvalue += content + queue

  // Ensure the content is followed by a newline and a valid marker.
  character = value.charAt(++index)
  marker = value.charAt(++index)

  if (character !== lineFeed || (marker !== equalsTo && marker !== dash)) {
    return
  }

  subvalue += character

  // Eat Setext-line.
  queue = marker
  depth = marker === equalsTo ? equalsToDepth : dashDepth

  while (++index < length) {
    character = value.charAt(index)

    if (character !== marker) {
      if (character !== lineFeed) {
        return
      }

      index--
      break
    }

    queue += character
  }

  if (silent) {
    return true
  }

  return eat(subvalue + queue)({
    type: 'heading',
    depth: depth,
    children: self.tokenizeInline(content, now)
  })
}

Version data entries

23 entries across 23 versions & 1 rubygems

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