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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)