Class: Paperwrap::Markdown

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

Instance Method Summary collapse

Constructor Details

#initialize(text, *extensions) ⇒ Markdown

Returns a new instance of Markdown.



9
10
11
12
# File 'lib/paperwrap/markdown.rb', line 9

def initialize(text, *extensions)
  @text = text
  @html_extensions = prepare_html_extensions(extensions) || []
end

Instance Method Details

#to_htmlObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/paperwrap/markdown.rb', line 14

def to_html
  # convert the Markdown text into HTML
  reader = java.io.StringReader.new @text
  writer = java.io.StringWriter.new
  html = ''
  begin
    m = org.tautua.markdownpapers.Markdown.new
    m.transform reader, writer
    writer.flush
  ensure
    reader.close if reader
    writer.close if writer
  end
  html = writer.to_string

  # apply html extensions
  apply_html_extensions html
end