Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Where to instantiate Redcarpet::Markdown in Rails? #184

samueller opened this Issue Dec 23, 2012 · 4 comments


None yet
5 participants

Is Markdown threadsafe? Should I be instantiating Redcarpet::Markdown for the entire Rails application? Or should I instantiate it once per web request?

Basically, where do I put the following code in my Rails application?

markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML

+1. I would also like to know.

Tuckie commented Feb 5, 2013

I use @@markdown ||= Redcarpet::Markdown.new(... to create a class variable within my helper. e.g :.

module RedcarpetHelper
  def markdown(content)
    @@markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)

mattr- commented Apr 4, 2013

Unless explicitly stated, you should not assume any library is thread safe. That being said, there is no thread safety that I've seen built into Redcarpet itself. Consider it not thread safe and follow @Tuckie's suggestion of a class variable that is memoized to be how you should do it.

@mattr- mattr- closed this Apr 4, 2013

bughit commented Nov 20, 2013

@mattr - if it's not thread safe why are you suggesting class variables? Are they not shared among threads?

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