html2text_ruby icon indicating copy to clipboard operation
html2text_ruby copied to clipboard

Fix nil output <a> name attribute conversion

Open logwolvy opened this issue 8 years ago • 3 comments

The attribute described(link below) was being converted incorrectly for certain pages I tried. https://www.w3schools.com/tags/att_a_name.asp

I created this gist based on the page I was trying to convert and before fix I was getting -

'<a name="sp">&nbsp;&nbsp;</a>' # => [ ]
'<a name="serno">87471742</a>' #> [87471742]

I admit this is really badly written non-html5 doc, but I really need to convert this for a project in production. After this fix, these conversions are fine. Kindly, merge this fix. Thanks!

logwolvy avatar Jan 21 '18 21:01 logwolvy

Thank you for the PR! Can you please include a test case that illustrates the change?

soundasleep avatar Jan 21 '18 21:01 soundasleep

Hi @soundasleep, I think we shouldn't convert 'a' tags to markdown like syntax when they have name attributes?

Example

# Expected Behavior
<a name="serno">87471742</a> #> 87471742
# Actual Behavior
<a name="serno">87471742</a> #> [87471742]

The actual behavior works well when the 'a' tag has an href attribute but for name attributes, it shouldn't add the square brackets. What do you think?

logwolvy avatar Mar 17 '18 21:03 logwolvy

I think your proposal is totally fine. If an <a> tag does not have any href, then it shouldn't display as a link. Can you write this into your commit and add a test case (or two) showing the difference, and get the test to pass on travis-ci? Thank you!

soundasleep avatar Mar 21 '18 22:03 soundasleep