Read more

Markdown-like emphasizing for text fields

Dominik Schöler
April 05, 2013Software engineer at makandra GmbH

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>.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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 14:31)