Skip to content

Instantly share code, notes, and snippets.

@Takazudo
Forked from peterhellberg/gfm.rb
Created March 27, 2012 15:25
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Takazudo/2216954 to your computer and use it in GitHub Desktop.
Save Takazudo/2216954 to your computer and use it in GitHub Desktop.
GitHub Flavored Markdown parser for use with Jekyll and Marked.app
#!/usr/bin/env ruby
require 'rubygems'
require 'redcarpet'
require 'pygments.rb'
class HTMLwithPygments < Redcarpet::Render::HTML
def block_code(code, language)
Pygments.highlight(code, :lexer => language.to_sym, :options => {
:encoding => 'utf-8'
})
end
end
def from_markdown(text)
markdown = Redcarpet::Markdown.new(HTMLwithPygments,
:fenced_code_blocks => true,
:no_intra_emphasis => true,
:autolink => true,
:strikethrough => true,
:lax_html_blocks => true,
:superscript => true,
:hard_wrap => false,
:tables => true,
:xhtml => false)
text.gsub!(/\{\{( *)?"(.*?)"\}\}/, '\1\2')
text.gsub!(/^\{% highlight (.+?) ?%\}(.*?)^\{% endhighlight %\}/m) do |match|
Pygments.highlight($2, :lexer => $1, :options => {:encoding => 'utf-8'})
end
markdown.render(text)
end
puts from_markdown(ARGF.read)
@JuanitoFatas
Copy link

excuse me, could you please tell me how to use this plugin?

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