jaytaylor / html2text

Golang HTML to plaintext conversion library
https://jaytaylor.com/html2text
MIT License
541 stars 138 forks source link

Preserve whitespace in <pre> tags #24

Closed helb closed 6 years ago

helb commented 6 years ago

Html2text seems to discard the whitespace formatting in <pre> tags:

input:

<pre>test1
test 2

test  3</pre>

expected:

test1
test 2

test  3

actual result:

test1 test 2 test 3

<pre> on MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre ("Whitespace inside this element is displayed as written.")

Code taken from this patch by @Kleissner: https://github.com/jaytaylor/html2text/issues/6#issuecomment-329620709Q, with atom.Code removed (as <code> does not actually preserve whitespace in browsers).

Added a simple test case with newlines and multiple spaces.

Fixes #6, also fixes #22.

jaytaylor commented 6 years ago

Beautiful, thanks @helb !