Sha256: f46b7f24b55daa63b7d9764d3867188fb6cf19cf703387ec24320fd07137bf1a

Contents?: true

Size: 634 Bytes

Versions: 3

Compression:

Stored size: 634 Bytes

Contents

require 'kramdown'
require_relative 'mastalk/extensions'

module Mastalk
  # Document class to preprocess
  # mastalk specific syntax
  class Document
    include Mastalk::Extensions

    attr_reader :source

    def initialize(source)
      @source = source.dup
    end

    def to_html
      kramdown.to_html
    end

    private

    def kramdown
      Kramdown::Document.new(preprocess(source))
    end

    def preprocess(source)
      extensions.map do |regex, block|
        if source.match(regex)
          source.gsub!(regex, block.call(Regexp.last_match.captures.first))
        end
      end
      source
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mastalk-0.1.2 lib/mastalk.rb
mastalk-0.1.1 lib/mastalk.rb
mastalk-0.1.0 lib/mastalk.rb