Sha256: c464fbbd7be65721941c399ac19c300fb1533c1869ff1163c29a0f84a05a61c2

Contents?: true

Size: 710 Bytes

Versions: 2

Compression:

Stored size: 710 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.sub!(regex, block.call(Regexp.last_match.captures.first))
        end
      end
      preprocess(source) if extensions.any? {|regex, _| source.match(regex)}
      source
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mastalk-0.2.1 lib/mastalk.rb
mastalk-0.2.0 lib/mastalk.rb