Reputation: 10224
How can I make simple_format not wrap the returned value in p tags?
simple_format "<span class="required">*</span>"
Upvotes: 12
Views: 6708
Reputation: 8695
There's a workaround, if you simply want to get rid of browser-styles:
simple_format "<span class="required">*</span>", {}, wrapper_tag: 'p style="margin: 0"'
…hackedy-hack-hack…
Upvotes: 0
Reputation: 2588
You can specify wrapper_tag
option.
simple_format 'Hello', {}, wrapper_tag: 'span'
This code will be:
<span>Hello</span>
Upvotes: 11
Reputation: 18853
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
Upvotes: 3
Reputation: 2924
Unfortunately -- you can't. If you check out the source at http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format you'll see that the p tags are wrapped around the content unconditionally.
You could create a helper that uses the simple_format code, but modify it to not include the p tags...
Upvotes: 10