You can build your own renderer (based on Redcarpet::Render::HTML
), which will override the methods you are interested in customizing:
Custom renderers are created by inheriting from an existing renderer. The built-in renderers,
HTML
andXHTML
may be extended as such:# create a custom renderer that allows highlighting of code blocks class HTMLwithPygments < Redcarpet::Render::HTML def block_code(code, language) Pygments.highlight(code, :lexer => language) end end markdown = Redcarpet::Markdown.new(HTMLwithPygments, :fenced_code_blocks => true)
But new renderers can also be created from scratch (see
lib/redcarpet/render_man.rb
for an example implementation of a Manpage renderer)
<<snip>>
The following instance methods may be implemented by the renderer:
<<snip>>
- table(header, body)
<<snip>>
- raw_html(raw_html)
For example, to enable markdown inside raw HTML, I would suggest declaring a <markdown>
element, which you can extract, and render (Warning - untested code ahead):
def raw_html(html)
html.gsub(/<markdown>(.*)<\/markdown>/) { render $1 }
end
Override these methods to either add the needed class to your table, or to recursively call render
from elements in your raw HTML.