ruby on rails redcarpet code block not respecting indentation

131 Views Asked by At

I am trying to use recarpet in a rails 5 application, everything works fine except for the fact that indentations are not respected in code blocks. I setup redcarpet in my ApplicationHelper file as Shawn below.

module ApplicationHelper
    def markdown(text)
        options = { 
          filter_html:     true,
          hard_wrap:       true,
          link_attributes: { rel: 'nofollow', target: "_blank" },
      space_after_headers: true,
      lax_html_blocks:    true,
          fenced_code_blocks: true
        }
    
        extensions = {
          autolink:           true,
          superscript:        true
        }
    
        renderer = Redcarpet::Render::HTML.new(options)
        markdown = Redcarpet::Markdown.new(renderer, extensions)
    
        markdown.render(text).html_safe
    end
end

then in my view I called the markdown method as <%= markdown(@blog.body) %> So when I post an article using my form, for example

def function
  return you are real
end

It renders in the browser as

def function
return you are real
end

thereby not respecting the indentation. I don't know if I am missing out on an option.

0

There are 0 best solutions below