In my Rails app, I have a textarea box that I want people to be able to use markdown on. The redcarpet gem works fine for purposes of rendering the markdown, but it appends it after the enclosing span. This screws up my design; the top of the paragraph should appear between the "play" icon and the "pencil" icon (same as the title is in this picture):
Here's the html.erb with the markdown
call. As you can see, it's entirely enclosed in a <span>
tag:
<p class="user_desc">
<span class="glyphicon glyphicon-play"></span>
<span class="glyphicon glyphicon-pencil"></span>
<span id="user_title_text"><%= markdown(@user.description) %></span>
</p>
Here is how the HTML is rendered via ERb and Redcarpet:
<p class="user_desc">
<span class="glyphicon glyphicon-play"></span>
<span class="glyphicon glyphicon-pencil"></span>
<span id="user_title_text"></span></p>
<p>
Hi! I started <a href="https://www.startthis.org" rel="nofollow"
target="_blank">StartThis.org</a>. My background is in philosophy (Ph.D.,
Ohio State, 2000). I like ideas and thinking them through. I also like
organizing things online, especially educational and reference projects.
</p>
(etc.)
In other words, the markdown
method is called (and I expected it to be interpolated in) span#user_title_text
, it was actually appended after the span.
What's the best way to fix this? I hunted for similar problems but couldn't find any. I guess I could prepare the HTML in a string in a helper method and pass it separately to the view (maybe? Nope, I just tried it and it has the same effect!), but what's the best practice/solution to this? Sorry if this is kind of obvious, I'm a noob to all this.
Thinking a little bit more, considering that preparing the parsed markdown in advance, in the controller, has the same effect, maybe the problem is with how rails/ERb does the interpolation?
TIA
UPDATE: Note the <p>
in the above code. This surrounded a span which surrounded the markdown call...which generates <p>
tags!
Also note the
in the code above. After fixing the <p>
tags (changed them to <div>
s), thanks to Matt's advice, I tried removing the html entities...and then it was fixed. Why?!
TIA again.
in
and in . So, I fixed that stuff up. But it still wasn't working--exact same problem. I couldn't understand why. Then I noticed the two ` ` html entities and on a hunch, I tried removing them. That fixed it!
– globewalldesk Nov 02 '17 at 00:14`s was definitely necessary (I tested that separately). But why on earth could those html entities also be part of the problem?! I'll add more details to my original question, and if you could explain in your answer I'll definitely check as the correct one.
– globewalldesk Nov 02 '17 at 00:24