Sha256: 2a8eff1f63513fee94cd0db27739137d7c9b9f92470be1f2026d2cd558911284

Contents?: true

Size: 768 Bytes

Versions: 18

Compression:

Stored size: 768 Bytes

Contents

require 'kramdown'
require 'htmlentities'
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
      ::HTMLEntities.new.decode( 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).strip)
        end
      end
      preprocess(source) if extensions.any? {|regex, _| source.match(regex)}
      source
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mastalk-0.6.0 lib/mastalk.rb
mastalk-0.5.9 lib/mastalk.rb
mastalk-0.5.8 lib/mastalk.rb
mastalk-0.5.7 lib/mastalk.rb
mastalk-0.5.6 lib/mastalk.rb
mastalk-0.5.5 lib/mastalk.rb
mastalk-0.5.4 lib/mastalk.rb
mastalk-0.5.3 lib/mastalk.rb
mastalk-0.5.2 lib/mastalk.rb
mastalk-0.5.1 lib/mastalk.rb
mastalk-0.5.0 lib/mastalk.rb
mastalk-0.4.0 lib/mastalk.rb
mastalk-0.3.5 lib/mastalk.rb
mastalk-0.3.4 lib/mastalk.rb
mastalk-0.3.3 lib/mastalk.rb
mastalk-0.3.2 lib/mastalk.rb
mastalk-0.3.1 lib/mastalk.rb
mastalk-0.3.0 lib/mastalk.rb