class HTML::Pipeline::RubyMarkup::MarkdownTraverser

To go through a markdown document. Mainly used to decide if we are in code blocks to decide if we should escape underscored usernames.

Constants

CODEBLOCK_MARKER

Attributes

current[RW]
lines[R]
prev[RW]

Public Class Methods

new(markdown) click to toggle source
# File lib/html/pipeline/ruby_markup/markdown_traverser.rb, line 9
def initialize(markdown)
  @lines = markdown.dup.lines
  init_position
end

Public Instance Methods

each() { |line| ... } click to toggle source
# File lib/html/pipeline/ruby_markup/markdown_traverser.rb, line 14
def each
  lines.each do |line|
    update_position(line.include?(CODEBLOCK_MARKER))
    yield(line)
  end
end
in_codeblock?() click to toggle source
# File lib/html/pipeline/ruby_markup/markdown_traverser.rb, line 21
def in_codeblock?
  prev == true && current == false
end

Private Instance Methods

init_position() click to toggle source
# File lib/html/pipeline/ruby_markup/markdown_traverser.rb, line 33
def init_position
  self.prev = false
  self.current = lines.first.include?(CODEBLOCK_MARKER)
end
update_position(current) click to toggle source
# File lib/html/pipeline/ruby_markup/markdown_traverser.rb, line 38
def update_position(current)
  self.current = current
  self.prev = current ? !prev : prev
end