Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3. simple_format do not wrap result in paragraph tags

How can I make simple_format not wrap the returned value in p tags?

simple_format "<span class="required">*</span>"

like image 443
leonel Avatar asked Jan 03 '12 20:01

leonel


2 Answers

Probably not what you really wanted, but... I ended up doing this:

module ApplicationHelper
  def nl2br s
    split_paragraphs(sanitize(s, tags: [])).join('<br>').html_safe
  end
end

UPD Or better this:

def nl2br s
  sanitize(s, tags: []).gsub(/\n/, '<br>').html_safe
end
like image 157
x-yuri Avatar answered Oct 02 '22 23:10

x-yuri


You can specify wrapper_tag option.

simple_format 'Hello', {}, wrapper_tag: 'span'

This code will be:

<span>Hello</span>
like image 36
Junichi Ito Avatar answered Oct 02 '22 23:10

Junichi Ito