How do I wrap HTML untagged text with <p> tag using Nokogiri?

人走茶凉 提交于 2019-11-30 21:51:21

After searching around some forums and doing some debugging locally, i have found the following solution to my problem.

html_doc = Nokogiri::HTML.parse('path/to/html_file')
html_doc
html_doc.search("//br/preceding-sibling::text()|//br/following-sibling::text()").each do |node|
    node.replace(Nokogiri.make("<p>#{node.to_html}</p>"))
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!