Insert in Rails with Nokogiri
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! p开发者_运维问答attern, 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 ?
Just guessing - maybe p.content.gsub! pattern, " ".html_safe
may help?
精彩评论