Skip to content

Instantly share code, notes, and snippets.

@nathany
Created February 17, 2013 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathany/4972801 to your computer and use it in GitHub Desktop.
Save nathany/4972801 to your computer and use it in GitHub Desktop.
Configuring Nesta CMS to use Redcarpet and Pygments.rb.
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