-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Feature propositon: target="_blank" option for external links #681
Comments
The idea itself makes sense to have at the |
As far I know no. What I propose is: With the option enabled [Linux](https://fr.wikipedia.org/wiki/Linux) Renders to <a href="https://fr.wikipedia.org/wiki/Linux" target="_blank" rel="noopener">Linux</a> And we can use standard html links for exception when we don't need to open in a new link |
It looks like Hugo has it as a markdown parser option: https://gohugo.io/getting-started/configuration/#configure-blackfriday (hrefTargetBlank). I think adding it as a config.toml field only (for now) is ok |
Hi @Keats, @z0mbie42 I've had a look into what might be required to implement this in the same spirit as Hugo's Adding a global option will likely mean that absolute links (even those referring to non-external locations) will be given blank targets. An alternative is to use a custom shortcode for external links which implements the blank target and "noopener" attribute itself - but this obviously puts the burden back on the user. OverviewIf a
Updated RenderingZola uses uses I'd propose changing the logic in the following section of code so that 'normal' links emit an zola/components/rendering/src/markdown.rs Lines 208 to 218 in b660649
The check for what constitutes a 'normal' link can be found in this function. ConclusionLet me know your thoughts on the high-level approach (and even if this is something to be pursued). I'd be happy to implement this in a PR for review if you'd like. |
Thanks @MichaelByrneAU ! cc @chris-morgan that might be interested in that |
See #695 for for another thing to add to that feature. |
Anyone working on that? |
I am now wondering if that should be an option of pulldown_cmark rather than Zola since that's a pretty common thing to want from a markdown renderer... cc @marcusklaas |
It may make sense. Can you open an issue on pulldown-cmark? That way we can get more input from other users/ contributors. |
I'm not sure what the status here is, but as a workaround I've been using the following JavaScript snippet. var enableTargetBlank = function() {
var parents = document.getElementsByClassName('with-target-blank');
for (let parent of parents) {
var links = parent.getElementsByTagName('a');
for (let link of links) {
if (link.hostname !== window.location.hostname && link.target === "") {
link.target = "_blank";
}
}
}
};
{% if config.extra.enable_target_blank %}
enableTargetBlank();
{% endif %} This is added to the base template, and I add the |
You can actually do this sort of thing in the template to a large extent. Instead of writing
Or perhaps this approach (which may be a shade more robust):
With my regular expression replacement filter (see #986), you could make it a shade more robust still. (I’m already doing involved replacements within content; if I wanted this functionality, I’d probably do it that way at present.) |
@chris-morgan I'm probably missing something (new zola user here), but I'm getting an error when trying out your solution:
am I doing something wrong here? Also, @Keats , what's the status of getting the config option suggested here? |
Sorry, I was careless there, Also a general note about Tera, its grammar is not as consistent as you might like, so I commonly hit places where you can’t write an expression there and must instead assign the expression to a temporary name with the likes of |
This is implemented in the |
Hi,
I would love to have an option which which would trasnform
to
(please note the
"noopener"
for security reasons).Instead of needing to write those HTML links manually.
Ideally it could be configurable at the site (
config.toml
) level or at the file (frontmatter) level.something like
Which would affect only external links.
I'm open to try to implement it if you are okay/busy.
Best regards,
Sylvain Kerkour
The text was updated successfully, but these errors were encountered: