开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜