Class: Literati::MarkdownRenderer
- Inherits:
-
Object
- Object
- Literati::MarkdownRenderer
- Defined in:
- lib/literati.rb
Overview
A simple class to wrap passing the right arguments to RedCarpet.
Defined Under Namespace
Classes: GitHubWrapper
Instance Method Summary collapse
- #determine_markdown_renderer ⇒ Object
-
#initialize(content) ⇒ MarkdownRenderer
constructor
Create a new compatibility instance.
- #installed?(file) ⇒ Boolean
-
#to_html ⇒ Object
Render the Markdown content to HTML.
Constructor Details
#initialize(content) ⇒ MarkdownRenderer
Create a new compatibility instance.
content - The Markdown content to render.
28 29 30 |
# File 'lib/literati.rb', line 28 def initialize(content) @content = content end |
Instance Method Details
#determine_markdown_renderer ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/literati.rb', line 32 def determine_markdown_renderer @markdown = if installed?('github/markdown') GitHubWrapper.new(@content) elsif installed?('redcarpet/compat') Markdown.new(@content, :fenced_code, :safelink, :autolink) elsif installed?('redcarpet') RedcarpetCompat.new(@content) elsif installed?('rdiscount') RDiscount.new(@content) elsif installed?('maruku') Maruku.new(@content) elsif installed?('kramdown') Kramdown::Document.new(@content) elsif installed?('bluecloth') BlueCloth.new(@content) end end |
#installed?(file) ⇒ Boolean
50 51 52 53 54 55 56 57 |
# File 'lib/literati.rb', line 50 def installed?(file) begin require file true rescue LoadError false end end |
#to_html ⇒ Object
Render the Markdown content to HTML. We use GFM-esque options here.
Returns an HTML string.
62 63 64 65 |
# File 'lib/literati.rb', line 62 def to_html determine_markdown_renderer @markdown.to_html end |