class Mastalk::Document

Document class to preprocess mastalk specific syntax

Attributes

source[R]

Public Class Methods

new(source) click to toggle source
# File lib/mastalk/document.rb, line 13
def initialize(source)
  @source = source.dup
end

Public Instance Methods

to_html(options = {}) click to toggle source
# File lib/mastalk/document.rb, line 17
def to_html(options = {})
  auto_ids = options[:auto_id].nil? ? true : options[:auto_ids]
  kramdown = Kramdown::Document.new(
    preprocess(source),
    auto_ids: auto_ids
  )
  html, _ = Kramdown::Converter::Html.convert(kramdown.root, kramdown.options)
  ::HTMLEntities.new.decode(html)
end

Private Instance Methods

preprocess(source) click to toggle source
# File lib/mastalk/document.rb, line 29
def preprocess(source)
  extensions.each do |regex, block|
    while source.match(regex)
      source.sub!(regex, block.call(Regexp.last_match.captures.first).strip)
    end
  end
  source
end