views:

53

answers:

1

Hi, i need to insert nbsp symbol in some places of the HTML, that comes from DB and will be displayed on the page.

I do following:

doc = Nokogiri::HTML( self.content )
doc.css("p").each do |p|
    p.content.gsub! pattern, " "
end

This resulting text contains nbsp, displayed as a plain text, but not a special symbol.

I also tried to use following:

p.content.gsub! pattern, "\u00A0"
p.content.gsub! pattern, " "
p.content.gsub! pattern, 160.chr # paragraph disappears in this case
p.content.gsub! pattern, "\240"  # paragraph disappears in this case

But they all do not work.

It seems, like "content" methods of Nokogiri node escapes special symbols, while modifiying the content or inner_text.

Is there any way to access raw node content ?

+1  A: 

Just guessing - maybe p.content.gsub! pattern, " ".html_safe may help?

gertas
Wow! Amazing solution! Much better, than using CGI.unescapeHTML(...) ! Thanks a lot, man !
AntonAL