Say you want to allow users to emphasize some string, but the whole markdown thing would be far too much. The helper method below does a basic replacement of **some text**
with <strong>some text</strong>
.
Usage: <%=md @question.title %>
.
def custom_markdown(prose)
markdown = String.new.html_safe
markdown << prose.to_str # make sure the prose gets escaped, even if it is an html_safe string
markdown.gsub(/(\*\*)(.*?)(\*\*)/, '<strong>\2</strong>').html_safe
end
alias_method :md, :custom_markdown
Posted by Dominik Schöler to makandra dev (2013-04-05 12:31)