Skip to content

Adding configuration option for target blank links #160

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

Closed
mbenoukaiss opened this issue Jan 8, 2025 · 1 comment
Closed

Adding configuration option for target blank links #160

mbenoukaiss opened this issue Jan 8, 2025 · 1 comment

Comments

@mbenoukaiss
Copy link

mbenoukaiss commented Jan 8, 2025

Would it be possible to add a CompileOptions entry to allow making all links target blank ?

I'd glady implement it but I'm not sure I understand how the library works and thus how to proceed. An idea I had would be to change the generate_autolink function and end up with something like the following :

pub const TARGET_SUPPORTED_PROTOCOLS: [&str; 2] = ["http", "https"];
fn generate_autolink(...) {
    ...

    if !context.image_alt_inside && (!is_in_link || !is_gfm_literal) {
        ...

        if context.options.target_blank_links
            && TARGET_SUPPORTED_PROTOCOLS.contains(protocol.unwrap_or("http")) {
            context.push("\" target=\"_blank\">");
        } else {
            context.push("\">");
        }
    }

    ...
}

Tell me if this is a good way to do it or how I can improve it and I can open a merge request with the changes if this is a desired functionality.

@wooorm
Copy link
Owner

wooorm commented Jan 8, 2025

Hi! No, that’s for plugins, #32.
I also think it’s probably not a good idea: https://css-tricks.com/use-target_blank/.
And if it was, looking for http is not good enough, it’s possible to make other links that go to the same or different domains, with or without http!

@wooorm wooorm closed this as completed Jan 8, 2025
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