1

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.

Andre Roy
  • 53
  • 7
  • 1
    The code block in `@blog.body` needs to either [have lines that start with 4 spaces](https://www.markdownguide.org/basic-syntax/#code-blocks) or it needs to be [fenced by 3 backticks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks). – cschroed Oct 28 '20 at 13:47
  • Ya that was exactly what I did but it rendered without spaces, but I solved the problem, I notice every block code should be at least two spaces away from other text or paragraphs for the indentation to be respected. fore example. paragraph............... 2 extra spaces block_code 2 extra spaces paragraph..... I don't know why but it works. – Andre Roy Nov 10 '20 at 20:32

0 Answers0