Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Prawndown! Super-tiny subset of Markdown for use with the Prawn PDF lib.
class Prawndown
constructor: (@text) ->
toPrawn: ->
replace(/\n/g, "<br>\n").
replace(/^# (.+)/gm, "<b>$1</b>")
# Use:
console.log (new Prawndown("# Foo\nbar")).toPrawn()
class Prawndown
def initialize(text)
@text = text
def to_prawn
@text.to_s.gsub(/^# (.+)/, '<b>\1</b>')
# Use in Prawn:
text ="# Foo\nbar").to_prawn
pdf =
pdf.text text, inline_format: true

olimart commented May 17, 2013

Hi, I came across your gist.

I followed your sample code but when I run pdf.text text, inline_format: true it returns => nil
(the first 2 steps work great)

I saved prawndown.rb in my models and under assets/javascripts

Any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment