aaronsw / html2text

Convert HTML to Markdown-formatted text.
http://www.aaronsw.com/2002/html2text/
GNU General Public License v3.0
2.57k stars 410 forks source link

Bug - Converting an <img> tag with a hypen in src and a src greater than 74 characters adds a newline after the hypen in the output #105

Open mkmoisen opened 7 years ago

mkmoisen commented 7 years ago

I noticed an odd bug when Converting an <img> tag containing:

Converting a <img> tag with a src of 74 characters or less works fine

> # Note the missing "y" in the last word, "supply"
>img = '<img src="http://matthewmoisen.com/blog/wp-content/matthew_moisen_tractor_suppl.jpg">'
>html2text.html2text(img)
u'![](http://matthewmoisen.com/blog/wp-content/matthew_moisen_tractor_suppl.jpg)\n\n'

> # Note the addition of the "y" in the last word, "supply"
>img = '<img src="http://matthewmoisen.com/blog/wp-content/matthew_moisen_tractor_supply.jpg">'
>html2text.html2text(img)
u'![](http://matthewmoisen.com/blog/wp-\ncontent/matthew_moisen_tractor_supply.jpg)\n\n'

See how a \n character has been added after wp- ?

Alir3z4 commented 7 years ago

@mkmoisen you might wanna have a look a this #91 The project has been moved to https://github.com/Alir3z4/html2text/

JQ-K commented 4 years ago

I noticed an odd bug when Converting an <img> tag containing:

  • A hyphen in the src
  • A src longer than 74 characters

Converting a <img> tag with a src of 74 characters or less works fine

> # Note the missing "y" in the last word, "supply"
>img = '<img src="http://matthewmoisen.com/blog/wp-content/matthew_moisen_tractor_suppl.jpg">'
>html2text.html2text(img)
u'![](http://matthewmoisen.com/blog/wp-content/matthew_moisen_tractor_suppl.jpg)\n\n'

> # Note the addition of the "y" in the last word, "supply"
>img = '<img src="http://matthewmoisen.com/blog/wp-content/matthew_moisen_tractor_supply.jpg">'
>html2text.html2text(img)
u'![](http://matthewmoisen.com/blog/wp-\ncontent/matthew_moisen_tractor_supply.jpg)\n\n'

See how a \n character has been added after wp- ?

HI, i have the same problem as you so how did you resolve it? thx

mkmoisen commented 4 years ago

@JQ-K Sorry I do not remember.

JQ-K commented 4 years ago

@JQ-K Sorry I do not remember. ok thx

durcheinandermann commented 3 years ago

I got around this issue by avoiding wrapping altogether. Using the bodywidth argument: html2text(html=str(soup), bodywidth=0)