-
-
Save ajmalafif/e7fcd57aafbca62dba223c7e79592e03 to your computer and use it in GitHub Desktop.
Prawndown! Super-tiny subset of Markdown for use with the Prawn PDF lib.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Prawndown | |
constructor: (@text) -> | |
toPrawn: -> | |
@text. | |
replace(/\n/g, "<br>\n"). | |
replace(/^# (.+)/gm, "<b>$1</b>") | |
# Use: | |
console.log (new Prawndown("# Foo\nbar")).toPrawn() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Prawndown | |
def initialize(text) | |
@text = text | |
end | |
def to_prawn | |
@text.to_s.gsub(/^# (.+)/, '<b>\1</b>') | |
end | |
end | |
# Use in Prawn: | |
text = Prawndown.new("# Foo\nbar").to_prawn | |
pdf = Prawn::Document.new | |
pdf.text text, inline_format: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment