Is it possible to convert HTML with Nokogiri to plain text? I also want to include <br />
tag.
For example, given this HTML:
<p>ala ma kota</p> <br /> <span>i kot to idiota </span>
I want this output:
ala ma kota
i kot to idiota
When I just call Nokogiri::HTML(my_html).text
it excludes <br />
tag:
ala ma kota i kot to idiota
If you use HAML you can solve html converting by putting html with 'raw' option, f.e.
Try
Instead of writing complex regexp I used Nokogiri.
Working solution (K.I.S.S!):
Nokogiri will strip out links, so I use this first to preserve links in the text version:
that will turn this:
to this:
Nothing like this exists by default, but you can easily hack something together that comes close to the desired output: