Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advice on Modifying html2text Behavior to Preserve Link Text #15

Closed
devstein opened this issue Oct 26, 2022 · 3 comments
Closed

Advice on Modifying html2text Behavior to Preserve Link Text #15

devstein opened this issue Oct 26, 2022 · 3 comments

Comments

@devstein
Copy link
Contributor

Hi 👋

Thanks for making and maintaining this package! It's almost exactly what I was looking for. The only different behavior I am looking for is to preserve the link text and append the link as a suffix to the text in the conversion.

For example, the behavior I want is

So(HTML2Text(`click <a href="javascript:void(0)">here</a>`), ShouldEqual, "click here")
So(HTML2Text(`click <a href="test"><span>here</span> or here</a>`), ShouldEqual, "click test <test>")
So(HTML2Text(`click <a href="http://bit.ly/2n4wXRs">news</a>`), ShouldEqual, "click news <http://bit.ly/2n4wXRs>")

I understand a change like would be breaking for users and change the interface, so I am planning on forking the repo to make this change.

Do you have advice on how to make this change? It's clear that changes would need to be made here. Any advice is appreciated!

@devstein
Copy link
Contributor Author

Took a stab at it 😁 PR is here

@k3a The only part I'm unsure of is this line.

Do I need to also look for tagNameLowercase == "a" or will the closing tag always be tagNameLowercase == "/a"

@k3a
Copy link
Owner

k3a commented Nov 7, 2022

Thanks for your contribution! I integrated it into the master in a backward-compatible way :) and kept the CI as well.

@k3a k3a closed this as completed Nov 7, 2022
@devstein
Copy link
Contributor Author

devstein commented Nov 7, 2022

Amazing! Glad I could help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants