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.



69
70
71
# File 'lib/troy/markdown.rb', line 69

def initialize(markup)
  @markup = markup
end

Instance Attribute Details

#markupObject (readonly)

Set the Markdown markup that must be rendered.



67
68
69
# File 'lib/troy/markdown.rb', line 67

def markup
  @markup
end

Instance Method Details

#rendererObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/troy/markdown.rb', line 73

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

#to_htmlObject



85
86
87
# File 'lib/troy/markdown.rb', line 85

def to_html
  renderer.render(markup)
end