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

Do not include href if href without protocol is same as text in link #271

Open
filipagh opened this issue Dec 16, 2022 · 4 comments
Open
Milestone

Comments

@filipagh
Copy link

filipagh commented Dec 16, 2022

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?

@KillyMXI
Copy link
Member

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.

@KillyMXI KillyMXI modified the milestones: Version 1.0.0, Version 9.1.0 Dec 16, 2022
@filipagh
Copy link
Author

filipagh commented Jan 9, 2023

hello @KillyMXI,
when you expect new version with this function,
or if you have idea how it may work i can contribute

@KillyMXI
Copy link
Member

KillyMXI commented Jan 9, 2023

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.

@Bessonov
Copy link

Bessonov commented Nov 25, 2024

I strongly disagree with the expectation described. Removing the protocol is wrong. It could be http, https, ftp, mailto, etc. Instead, I suggest only skipping if the reference and the text are exactly the same:

input - please use <a href="http://www.google.com">www.google.com</a> to search
Expected: "please use www.google.com [http://www.google.com] to search" (current state)
 input - please use <a href="http://www.google.com">http://www.google.com</a> to search
-Received: "please use http://www.google.com [http://www.google.com] to search"
+Expected: "please use http://www.google.com to search"

EDIT: forgot to say, that this is already the case with hideLinkHrefIfSameAsText option.

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

3 participants