Class: Malt::Engine::Redcarpet

Inherits:
Abstract show all
Defined in:
lib/malt/engines/redcarpet.rb

Overview

Redcarpet Markdown implementation.

Instance Attribute Summary

Attributes inherited from Abstract

#settings

Instance Method Summary collapse

Methods inherited from Abstract

#cache?, default, #initialize, #prepare_engine, register, type

Constructor Details

This class inherits a constructor from Malt::Engine::Abstract

Instance Method Details

#create_engine(params = {}) ⇒ Object

Convert Markdown text to intermediate object.

Parameters:

  • params (Hash) (defaults to: {})

    A hash containing the Markdown extensions which the parser will identify. The following extensions are accepted.

Options Hash (params):

  • :no_intra_emphasis (Boolean)

    Do not parse emphasis inside of words. Strings such as ‘foo_bar_baz` will not generate `<em>` tags.

  • :tables (Boolean)

    Parse tables, PHP-Markdown style.

  • :fenced_code_blocks (Boolean)

    Parse fenced code blocks, PHP-Markdown style. Blocks delimited with three or more ‘~` or backticks will be considered as code, without the need to be indented. An optional language name may be added at the end of the opening fence for the code block

  • :autolink (Boolean)

    parse links even when they are not enclosed in ‘<>` characters. Autolinks for the http, https and ftp protocols will be automatically detected. Email addresses are also handled, and http links without protocol, but starting with `www.`

  • :strikethrough (Boolean)

    parse strikethrough, PHP-Markdown style Two ‘~` characters mark the start of a strikethrough, e.g. `this is ~~good~~ bad`

  • :lax_html_blocks (Boolean)

    HTML blocks do not require to be surrounded by an empty line as in the Markdown standard.

  • :space_after_headers (Boolean)

    A space is always required between the hash at the beginning of a header and its name, e.g. ‘#this is my header` would not be a valid header.

  • :superscript (Boolean)

    parse superscripts after the ‘^` character; contiguous superscripts are nested together, and complex values can be enclosed in parenthesis, e.g. `this is the 2^(nd) time`



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/malt/engines/redcarpet.rb', line 83

def create_engine(params={})
  return create_engine_1x(params) if ::Redcarpet::VERSION < '2'

  into, toc = parameters(params, :to, :toc)

  opts = engine_options(params)

  case into
  when :man, :manpage
    renderer = ::Redcarpet::Render::ManPage
  else
    if toc
      renderer = ::Redcarpet::Render::HTML_TOC
    else
      renderer = ::Redcarpet::Render::HTML
    end
  end

  cached(into, toc, opts) do
    ::Redcarpet::Markdown.new(renderer)
  end
end

#create_engine_1x(params = {}) ⇒ Object

For Recarpet v1.x.



107
108
109
110
111
112
113
# File 'lib/malt/engines/redcarpet.rb', line 107

def create_engine_1x(params={})
  text = parameters(params, :text)

  cached(text) do
    ::Redcarpet.new(text) #, engine_options(params))
  end
end

#render(params = {}) ⇒ Object

Convert Markdown text to HTML text.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :text (String)

    Template text

  • :to (String, Symbol) — default: 'html'

    Type or file extension to convert template into.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/malt/engines/redcarpet.rb', line 23

def render(params={})
  into, text = parameters(params, :to, :text)

  case into
  when :html, nil  # :man, :manpage
    if ::Redcarpet::VERSION < '2'
      prepare_engine(params).to_html
    else
      prepare_engine(params).render(text)
    end
  else
    super(params)
  end
end