Here's the input HTML:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
If I pass that through Rails' simple_format
the output is:
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
<p><ul>
<br /> <li>Item 1</li>
<br /> <li>Item 2</li>
<br /> <li>Item 3</li>
</ul></p>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
Notice the <br />
's before each list item.
How can I get simple_format
to not do that?
Ultimately what I want to do is add paragraph tags around content that isn't already wrapped in some sort of tag (ie. blockquote, ul, ol).
I hit the same problem. Here's how to solve it!
Wrap the simple_format output in a div like this:
<div class="single-spacing">
<%= simple_format @your_content %>
</div>
Then add this to your CSS file:
.single-spacing {
ul br {
display: none;
}
}
Or, when you actually want some br
inside a list, you can add this CSS instead:
.single-spacing{
ul li br:first-child, ol li br:first-child {
display: none;
}
}
I tried to add this as a class to the simple_format itself (which is an option), but it didn't work for some reason. Putting it in a DIV does.
Not sure why simple_format adds these extra
's to a simple list, but hey ho.
Michael
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With