mzee99
mzee99

Reputation: 191

Converting HTML Entity to Raw HTML

I have this string:

'<div class="md"><p><a href="http://www.google.com/">Foo</a></p> </div>'

which I'm trying to display as:

Foo

So I'm trying to convert the original string to raw HTML.

I've tried:

raw '<div class="md"><p><a href="http://www.google.com/">Foo</a></p> </div>'

which converts the entity to normal HTML but displays it as a string:

<div class="md"><p><a href="http://www.google.com/">Foo</a></p> </div>

I've also tried html_safe and html_safe.html_safe but those are giving me the same results.

So how do I convert a string containing HTML entities to raw HTML to be rendered in Rails?

Thanks

Upvotes: 2

Views: 1348

Answers (1)

jljohnstone
jljohnstone

Reputation: 1230

Try something like this:

CGI.unescapeHTML('&lt;div class="md"&gt;&lt;p&gt;&lt;a href="http://www.google.com/"&gt;Foo&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;').html_safe

Upvotes: 7

Related Questions