Skip to content

@lfborjas /replacer.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'hpricot'
require 'coderay'
require 'rdiscount'
#open the file in markdown
f = File.open "tmp.markdown"
#generate html with rdiscount
md = RDiscount.new f.read
#parse it with hpricot and be magical
d = Hpricot md.to_html
d.search "pre" do |code|
lang = ""
lines = code.innerText.split "\n"
lines.each do |line|
if line[0..2] == "@@@"
lang = line.gsub "@@@", ''
break
end
end
#ok, we have the lang, now, color it
newhtml = Hpricot CodeRay.scan(lines[1..-1].join("\n"), lang.to_sym).div :line_numbers => :inline
d.replace_child code, newhtml
end
fn = File.new "tmp_coded.html", 'w'
fn.write d.to_s
fn.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.