xijo / reverse_markdown

Ruby gem to convert html into markdown
Do What The F*ck You Want To Public License
629 stars 118 forks source link

ReverseMarkdown::Cleaner#clean_tag_borders aggressive with cleanup #52

Closed arunthampi closed 9 years ago

arunthampi commented 9 years ago

Found a bug caused by the clean_tag_borders method which does this:

>> require 'reverse_markdown'
=> true
>> ReverseMarkdown.convert('<html><body><a href="http://blog.99.co/wp-content/uploads/2014/04/suomayamuseum_mexico_city.jpg__1072x0_q85_upscale.jpg">test</a></body></html>')
=> " [test](http://blog.99.co/wp-content/uploads/2014/04/suomayamuseum_mexico_city.jpg__1072x0_q85_upscale.jpg)"
>> ReverseMarkdown.convert('<a href="http://blog.99.co/wp-content/uploads/2014/04/tohoku_earthquake_tsunami_japan.jpg__1072x0_q85_upscale.jpg"><img class="alignnone size-full wp-image-160" alt="tohoku_earthquake_tsunami_japan.jpg__1072x0_q85_upscale" src="http://blog.99.co/wp-content/uploads/2014/04/tohoku_earthquake_tsunami_japan.jpg__1072x0_q85_upscale.jpg" width="1072" height="603" /></a>')
=> " [![tohoku_earthquake_tsunami_japan.jpg __1072x0_q85_upscale](http://blog.99.co/wp-content/uploads/2014/04/tohoku_earthquake_tsunami_japan.jpg__ 1072x0_q85_upscale.jpg)](http://blog.99.co/wp-content/uploads/2014/04/tohoku_earthquake_tsunami_japan.jpg__1072x0_q85_upscale.jpg)"

Notice the extra space added between the two __ in the links and hence the link is broken. Looking at a fix now, will submit a pull request if I find something quick.

arunthampi commented 9 years ago

Here's a fix that fixes my issue (along with a test case): https://github.com/xijo/reverse_markdown/pull/53

arunthampi commented 9 years ago

thanks for the great gem btw!

xijo commented 9 years ago

Hello @arunthampi thanks for the report and the PR, I'll take a look at it.

xijo commented 9 years ago

@arunthampi I just release 0.8.2 with your fix. Thanks again and have a nice weekend.