Class: Troy::Markdown

Inherits:
Object
  • Object
show all
Defined in:
lib/troy/markdown.rb

Defined Under Namespace

Modules: PrismJs, Rouge Classes: Renderer

Constant Summary collapse

HEADING_ID =

Match the id portion of a header, as in ‘# Title #custom-id`.

/^(?<text>.*?)(?: {#(?<id>.*?)})?$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(markup) ⇒ Markdown

Returns a new instance of Markdown.

[View source]

102
103
104
# File 'lib/troy/markdown.rb', line 102

def initialize(markup)
  @markup = markup
end

Instance Attribute Details

#markupObject (readonly)

Set the Markdown markup that must be rendered.


100
101
102
# File 'lib/troy/markdown.rb', line 100

def markup
  @markup
end

Instance Method Details

#rendererObject

[View source]

106
107
108
109
110
111
112
113
114
115
# File 'lib/troy/markdown.rb', line 106

def renderer
  @renderer ||= Redcarpet::Markdown.new(Renderer,
                                        autolink: true,
                                        space_after_headers: true,
                                        fenced_code_blocks: true,
                                        footnotes: true,
                                        tables: true,
                                        strikethrough: true,
                                        highlight: true)
end

#to_htmlObject

[View source]

117
118
119
# File 'lib/troy/markdown.rb', line 117

def to_html
  renderer.render(markup)
end