Created
February 17, 2013 18:57
-
-
Save nathany/4972801 to your computer and use it in GitHub Desktop.
Configuring Nesta CMS to use Redcarpet and Pygments.rb.
This file contains 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
require 'redcarpet' | |
require 'pygments' | |
class Syntactical < Redcarpet::Render::HTML | |
include Redcarpet::Render::SmartyPants | |
def block_code(code, language) | |
Pygments.highlight(code, lexer: language) | |
end | |
end | |
class SyntacticalTemplate < Tilt::RedcarpetTemplate::Redcarpet2 | |
def generate_renderer | |
Syntactical.new(hard_wrap: false, with_toc_data: true) | |
end | |
def prepare | |
# override the options to include code fencing, etc. | |
opts = { | |
no_intra_emphasis: true, | |
tables: true, | |
fenced_code_blocks: true, | |
autolink: true, | |
strikethrough: true, | |
lax_html_blocks: true, | |
space_after_headers: false, | |
superscript: true | |
} | |
@engine = Redcarpet::Markdown.new(generate_renderer, opts) | |
@output = nil | |
end | |
end | |
Tilt::register SyntacticalTemplate, 'mdown' | |
Tilt.prefer SyntacticalTemplate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment