Skip to content

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

@filipagh

Description

@filipagh

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions