Module: PrawndownExt::Interface
- Defined in:
- lib/prawndown-ext.rb
Defined Under Namespace
Classes: CommandInterface
Instance Method Summary collapse
-
#markdown(string, options: {}) ⇒ Object
Renders Markdown in the current document.
- #unescape_text(text) ⇒ Object
Instance Method Details
#markdown(string, options: {}) ⇒ 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
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/prawndown-ext.rb', line 80 def markdown(string, options: {}) if !.key?("default_line_spacing") ["default_line_spacing"] = 0 end processed = PrawndownExt::Parser.new(string, ).to_prawn processed.each do |output| begin object = JSON.parse(output.strip) CommandInterface.new.exec object, self, rescue text unescape_text(output), inline_format: true, leading: ["default_line_spacing"].to_f end end end |
#unescape_text(text) ⇒ Object
67 68 69 |
# File 'lib/prawndown-ext.rb', line 67 def unescape_text text text = text.gsub('\\"', '"') end |