Class: HTML::Pipeline::MarkdownFilter

Inherits:
TextFilter show all
Defined in:
lib/html/pipeline/markdown_filter.rb

Overview

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

This filter does not write any additional information to the context hash.

Instance Attribute Summary

Attributes inherited from TextFilter

#text

Attributes inherited from Filter

#context, #result

Instance Method Summary collapse

Methods inherited from Filter

#base_url, call, #can_access_repo?, #current_user, #doc, #has_ancestor?, #html, #needs, #parse_html, #repository, to_document, to_html, #validate

Constructor Details

#initialize(text, context = nil, result = nil) ⇒ MarkdownFilter

Returns a new instance of MarkdownFilter.



14
15
16
17
# File 'lib/html/pipeline/markdown_filter.rb', line 14

def initialize(text, context = nil, result = nil)
  super text, context, result
  @text = @text.gsub "\r", ''
end

Instance Method Details

#callObject

Convert Markdown to HTML using the best available implementation and convert into a DocumentFragment.



21
22
23
24
25
26
# File 'lib/html/pipeline/markdown_filter.rb', line 21

def call
  mode = (context[:gfm] != false) ? :gfm : :markdown
  html = GitHub::Markdown.to_html(@text, mode)
  html.rstrip!
  html
end