Sha256: 00a1fb91ed6ff4129d10522774b0a63b6f39e983436046d02a6c9996cf240799

Contents?: true

Size: 646 Bytes

Versions: 3

Compression:

Stored size: 646 Bytes

Contents

module MarukuParser
  extend self

  def self.parse(markdown)
    html = Maruku.new(markdown, :on_error => :raise).to_html
    doc = Nokogiri::HTML::DocumentFragment.parse(html)
    code_blocks(doc)
    doc
  end

  # This parser seem to deal correctly with tags inside HTML comments
  def self.remove_tags_inside_html_comments(markdown)
    markdown
  end

  private

  def self.code_blocks(doc)
    doc.css('pre>code').each do |node|
      if match = node.content.match(/\A\s*:::\s*(\w+)/)
        lang = match[1]
        node.content = node.content.gsub(/\A\s*:::\s*\w+\n/, '')
        node['class'] = lang
      end
    end
    doc
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
devcenter-parser-1.4.9 lib/devcenter-parser/maruku_parser.rb
devcenter-parser-1.4.8 lib/devcenter-parser/maruku_parser.rb
devcenter-parser-1.4.7 lib/devcenter-parser/maruku_parser.rb