node-html-to-text
                                
                                 node-html-to-text copied to clipboard
                                
                                    node-html-to-text copied to clipboard
                            
                            
                            
                        Do not include href if href without protocol is same as text in link
Problem to solve What kind of problem you were trying to solve when you realized there is a missing feature? replace old custom regex for proper lib but try to not make visual changes.
so missing feature: add option to skip adding href as text if href without protocol is same as text of link
input - please use <a href="http://www.google.com">www.google.com</a> to search
Expected: "please use www.google.com to search"
Received: "please use www.google.com (http://www.google.com) to search"
if text is not same as href without protocol then add href
input - please use <a href=\"http://www.google.com\">gugl</a> to search
Expected and Received:  "please use gugl (http://www.google.com) to search"
What works
How close to your goal you can currently get?
see example,
now we have custom anchor formatter, but its code duplication from lib (whole formatAnchorfunc)  which is not good and i think this option is handy
What is missing
What prevents you from achieving your goal?
more robust hideSameLink option
How the missing feature should be implemented
Explain any technical details here.
in formatAnchor parse href without protocol and compare it with text case-insensitive
const hideSameLink = formatOptions.hideLinkHrefIfSameAsText && (getHrefWithoutProtocol(href) === text.toLowerCase() || href === text);
or change options hideSameLink to have multiple "hide" levels
or add its own options
Bigger picture Do you think this feature has different uses? Is there a better way to do it? What other options you've considered?
Thank you. Yes, this seems like a good behavior to have. It might also be handy to have an option for a predicate to decide whether the link needs to be shown. I'll think how I want to implement it and will likely implement it in 9.1.0.
hello @KillyMXI, when you expect new version with this function, or if you have idea how it may work i can contribute
Hello, This will be a part of the milestone Version 9.1.0. I'm planning to solve the other (upstream) issue first. And before that, I'm currently working on something for higher upstream package.
The set of options for anchor formatter is pretty chaotic. I thought to use this issue as an opportunity to come up with something better, to minimize the number of deprecated options I'd have to support with gradual change. The design isn't crystallized yet. The amount of code is very small, thinking on the design is what makes me delay it.