Skip to content

Instantly share code, notes, and snippets.

@schinckel
Created January 9, 2012 14:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save schinckel/1583152 to your computer and use it in GitHub Desktop.
Save schinckel/1583152 to your computer and use it in GitHub Desktop.
Jekyll renderer for Marked.app
#!/usr/bin/ruby
# Github-flavored markdown to HTML, in a command-line util.
#
# $ cat README.md | ./ghmarkdown.rb
#
# Notes:
#
# You will need to install Pygments for syntax coloring
#
# $ pip install pygments
#
# Install the gems rdiscount, albino, and nokogiri
#
# To work with http://markedapp.com/ I also had to
# $ sudo ln -s /usr/local/bin/pygmentize /usr/bin
#
require 'rubygems'
require 'rdiscount'
require 'albino'
require 'nokogiri'
require 'enumerator'
def markdown(text)
options = [:smart,]
text.gsub!(/---(.*)---/m, '')
# Replace {% highlight lang [linenos] %}<data>{% endhighlight %} with colourised code.
text.gsub!(/\{\{( *)?"(.*?)"\}\}/, '\1\2')
text.gsub!(/^\{% highlight (.+?) (linenos)? ?%\}(.*?)^\{% endhighlight %\}/m) do |match|
data = Albino.colorize($3, $1).to_s
if $2
pre, data, post = data.split(/<.?pre>/)
# data.gsub!(/^(.+)/, '<span class="lineno">#</span>\1')
data = data.split(/\n/)
data = data.each_with_index.map do |line, index|
"<span class='lineno'>#{index + 1}</span>#{line}\n"
end
data = "#{pre}<pre>#{data}</pre>#{post}"
end
data
end
RDiscount.new(text, *options).to_html
end
puts markdown(ARGF.read)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment