Can markdown be embedded inside erb?

If you use the haml viewer template as rails, you can write down part of your page with markdowns using the ": markdown" filter.

Is it possible to do the same with erb?

+3
source share
2 answers

There is no filtering in ERB like this built-in. You will need to directly use a gem that processes it, such as RDiscount or the venerable BlueCloth.

+1
source

, , , - Rails, #capture, #concat #markdown . , Maruku:

def markdown_filter(&block)
  concat(markdown(capture(&block)))
end

:

<% markdown_filter do %>
# Title

This is a *paragraph*.

This is **another paragraph**.
<% end %>

. -, , ; , , helper . -, Rails '#markdown, ( Maruku Markdown ):

def markdown(text)
  Maruku.new(text).to_html
end

Rails 3 #markdown, , Markdown .

+9

Source: https://habr.com/ru/post/1747571/


All Articles