require 'github/markdown'

module GitHub::HTML
  # HTML Filter that converts Markdown text into HTML and converts into a
  # DocumentFragment. This is different from most filters in that it can take a
  # non-HTML as input. It must be used as the first filter in a pipeline.
  #
  # Context options:
  #   :gfm      => false    Disable GFM line-end processing
  #   :autolink => false    Disable autolinking URLs
  #
  # This filter does not write any additional information to the context hash.
  class MarkdownFilter < Filter
    def initialize(text, context={})
      raise TypeError, "text cannot be HTML" if text.is_a?(DocumentFragment)
      @text = text.to_s.gsub("\r", '')
      @context = context
      @doc = nil
    end

    # Convert Markdown to HTML using the best available implementation
    # and convert into a DocumentFragment.
    def call
      flags = (context[:autolink] == false) ? [] : [:autolink]
      flags << :fenced_code << :tables << :strikethrough
      flags << :hard_wrap if context[:gfm] != false
      html = GitHub::Markdown.new(@text, *flags).to_html
      @doc = parse_html(html)
    end
  end
end

require 'github/markdown'

module GitHub::HTML
  # HTML Filter that converts Markdown text into HTML and converts into a
  # DocumentFragment. This is different from most filters in that it can take a
  # non-HTML as input. It must be used as the first filter in a pipeline.
  #
  # Context options:
  #   :gfm      => false    Disable GFM line-end processing
  #   :autolink => false    Disable autolinking URLs
  #
  # This filter does not write any additional information to the context hash.
  class MarkdownFilter < Filter
    def initialize(text, context={})
      raise TypeError, "text cannot be HTML" if text.is_a?(DocumentFragment)
      @text = text.to_s.gsub("\r", '')
      @context = context
      @doc = nil
    end

    # Convert Markdown to HTML using the best available implementation
    # and convert into a DocumentFragment.
    def call
      flags = (context[:autolink] == false) ? [] : [:autolink]
      flags << :fenced_code << :tables << :strikethrough << :lax_htmlblock
      flags << :hard_wrap if context[:gfm] != false
      html = GitHub::Markdown.new(@text, *flags).to_html
      @doc = parse_html(html)
    end
  end
end

Enable :lax_htmlblock when parsing MD
Enable :lax_htmlblock when parsing MD

Although the MD standard specifies that inline HTML blocks must be
surrounded by blank lines before and after the block, the Markdown.pl
parser does not honor this. We use the `lax_htmlblock` flag to mimic the
output of the official parser, so now blocks like

	This is a paragraph
	<pre>
		this is an inline html block
	</pre>
	This is another paragraph

are considered inline blocks.
