Class: Mdify::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/mdify/renderer.rb

Constant Summary collapse

MARKDOWN_OPTIONS =
{
  autolink: true,
  fenced_code_blocks: true,
  tables: true,
  strikethrough: true,
  superscript: true,
  no_intra_emphasis: true,
  space_after_headers: true
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Renderer

Returns a new instance of Renderer.



17
18
19
20
# File 'lib/mdify/renderer.rb', line 17

def initialize(filename)
  @title = File.basename(filename)
  @content = File.read(filename)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



15
16
17
# File 'lib/mdify/renderer.rb', line 15

def content
  @content
end

#titleObject (readonly)

Returns the value of attribute title.



15
16
17
# File 'lib/mdify/renderer.rb', line 15

def title
  @title
end

Instance Method Details

#renderObject



22
23
24
25
26
27
# File 'lib/mdify/renderer.rb', line 22

def render
  markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, MARKDOWN_OPTIONS)
  html = markdown.render(@content)
  document = render_html(@title, html)
  open_in_browser(write_html(document))
end