Module: PrawndownExt::Interface
- Defined in:
- lib/prawndown-ext.rb
Defined Under Namespace
Classes: CommandInterface
Instance Method Summary collapse
-
#markdown(string, options: nil) ⇒ Object
Renders Markdown in the current document.
- #unescape_text(text) ⇒ Object
Instance Method Details
#markdown(string, options: nil) ⇒ Object
Renders Markdown in the current document
It supports header 1-6, bold text, italic text, strikethrough and links It supports the same options as Prawn::Document#text
Prawn::Document.generate('markdown.pdf') do
markdown '# Welcome to Prawndown!'
markdown '**Important:** We _hope_ you enjoy your stay!'
end
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/prawndown-ext.rb', line 65 def markdown(string, options: nil) processed = PrawndownExt::Parser.new(string, ).to_prawn processed.each do |output| begin CommandInterface.new.exec JSON.parse(output.strip), self rescue text unescape_text(output), inline_format: true end end end |
#unescape_text(text) ⇒ Object
52 53 54 |
# File 'lib/prawndown-ext.rb', line 52 def unescape_text text text = text.gsub('\\"', '"') end |