class MarkdownIt::ParserBlock

Constants

RULES

Attributes

ruler[RW]

Public Class Methods

new() click to toggle source

new ParserBlock()

# File lib/motion-markdown-it/parser_block.rb, line 30
def initialize
  # ParserBlock#ruler -> Ruler
  #
  # [[Ruler]] instance. Keep configuration of block rules.
  @ruler = Ruler.new

  RULES.each do |rule|
    @ruler.push(rule[0], rule[1], {alt: (rule[2] || []) })
  end
end

Public Instance Methods

parse(src, md, env, outTokens) click to toggle source

ParserBlock.parse(src, md, env, outTokens)

Process input string and push block tokens into `outTokens`

# File lib/motion-markdown-it/parser_block.rb, line 100
def parse(src, md, env, outTokens)

  return if !src

  state = RulesBlock::StateBlock.new(src, md, env, outTokens)

  tokenize(state, state.line, state.lineMax)
end
tokenize(state, startLine, endLine, ignored = false) click to toggle source

Generate tokens for input range

# File lib/motion-markdown-it/parser_block.rb, line 44
def tokenize(state, startLine, endLine, ignored = false)
  rules         = @ruler.getRules('')
  len           = rules.length
  line          = startLine
  hasEmptyLines = false
  maxNesting    = state.md.options[:maxNesting]

  while line < endLine
    state.line = line = state.skipEmptyLines(line)
    break if line >= endLine

    # Termination condition for nested calls.
    # Nested calls currently used for blockquotes & lists
    break if state.sCount[line] < state.blkIndent

    # If nesting level exceeded - skip tail to the end. That's not ordinary
    # situation and we should not care about content.
    if state.level >= maxNesting
      state.line = endLine
      break
    end

    # Try all possible rules.
    # On success, rule should:
    #
    # - update `state.line`
    # - update `state.tokens`
    # - return true
    0.upto(len - 1) do |i|
      ok = rules[i].call(state, line, endLine, false)
      break if ok
    end

    # set state.tight if we had an empty line before current tag
    # i.e. latest empty line should not count
    state.tight = !hasEmptyLines

    # paragraph might "eat" one newline after it in nested lists
    if state.isEmpty(state.line - 1)
      hasEmptyLines = true
    end

    line = state.line

    if line < endLine && state.isEmpty(line)
      hasEmptyLines = true
      line += 1
      state.line = line
    end
  end
end