RedCloth Monkey Patching for Prism

March 25, 2015

So, I made some changes to this sites layout. One of them was to try using the Prism syntax highlighter for any code in these posts.

The trouble is, Prism doesn’t work correctly with the RedCloth gem I use for these posts.

So I sat down and monkey patched RedCloth so that it would. Here’s the gist of it…

bc(language-ruby).. # RedCloth doesn’t work well with the Prism syntax highlighting lirbary due to the way it handles blocks when it comes to newlines using bc.. # But we can add a config/initializers/redcloth.yml file to our Rails app and monkey patch it so it does. # # So, this monkey patch is to make RedCloth not split the bc.. code blocks on newlines. # To actually use it with Prism the syntax should look like this: # bc(language-ruby).. whatever multi-line code you want to display goes here module RedCloth::Formatters::HTML def bc_open(opts) opts[:block] = true “<pre#{pba(opts)}>” end

def bc_close(opts) “</pre>” end

def code(opts) “#{opts[:text]}” end end

And now, I can syntax highlight shit!


James Hagerman

Written by James Hagerman

© 2026