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

Open relative link in new tab does not work with instant loading #1609

Closed
4 tasks done
pamelasarkisyan opened this issue Apr 16, 2020 · 12 comments
Closed
4 tasks done
Labels
bug Issue reports a bug

Comments

@pamelasarkisyan
Copy link

I checked that...

  • ... the documentation does not mention anything about my problem
  • ... the problem doesn't occur with the default MkDocs template
  • ... the problem is not in any of my customizations (CSS, JS, template)
  • ... there are no open or closed issues that are related to my problem

Description

Open relative link in new tab does not work.

[As specified in the checks I did remove the theme and check the behaviour using just mkdocs without any theme and the links are opening correctly in another tab.]

Expected behavior

Relative link should open in new tab.

Actual behavior

Relative link opens in same tab/page.

https://3os.org/markdownCheatSheet/links/#link_with_open_in_new_tab
This is a live site using the theme and when you click on Relative Link With New Tab you will see the behavior.

Steps to reproduce the bug

Option 1:
Create an .md file inside docs/ and add link to any page:
[link](../another-page.md){target=_blank}
or
[link](../another-page.md){:target="_blank"}

Option 2:
Create an .md file inside docs/ and add full link to a page on a site which has the same domain:
[link](https://yourdomain.com/){target=_blank}
or
[link](../another-page.md){:target="_blank"}

Package versions

  • Python: Python 3.8.2
  • MkDocs: version 1.1
  • Material: Version: 5.1.0

Project configuration

# Project information
site_name: 'xyz'
site_description: 'xyz'
site_url: 'xyz'

#nav
<!-- not included -->

#theme options
theme:
  name: 'material'
  favicon: 'icons/favicon.png'
  features:
    - tabs
    - instant

#extensions
markdown_extensions:
  - admonition
  - codehilite:
      guess_lang: false
      use_pygments: true
  - pymdownx.superfences
  - toc:
      permalink: true
      toc_depth: 3
  - attr_list

System information

  • OS: Any
  • Browser: Any
@facelessuser
Copy link
Contributor

Does this happen when you turn off instant?

@pamelasarkisyan
Copy link
Author

Does this happen when you turn off instant?

Awesome! It did indeed fix the behaviour and the link now opens in another tab.

@facelessuser
Copy link
Contributor

Yeah, instant is pretty cool, but it is still experimental. I think there is still a bit that still needs to be worked out.

@squidfunk
Copy link
Owner

Nice catch! Haven't thought of target=_blank. Should be quite easy to fix. I'll look into it.

@squidfunk squidfunk added the bug Issue reports a bug label Apr 16, 2020
@squidfunk squidfunk changed the title Open relative link in new tab does not work. Open relative link in new tab does not work with instant loading Apr 16, 2020
@squidfunk
Copy link
Owner

Fixed in e96657c

@squidfunk
Copy link
Owner

... and released as part of 5.1.1

@blakegearin
Copy link

I'd like to point out that this hyperlink syntax (e.g. [link](https://yourdomain.com/){target=_blank}) doesn't work without attr_list

# mkdocs.yml

...
markdown_extensions:
  - attr_list
...

Would be nice if this was mentioned somewhere, perhaps under Formatting 🙂

@koen-yesplan
Copy link

  • I'd like to point out that attr_list is part of the extra extension, so no need to add the former if the latter is already in your yml file. See Markdown Extensions
  • When using reference links, I only got it working using the syntax [just a link][123]{: target='_blank'}. [just a link][123]{target=_blank} didn't seem to work.

@scmcca
Copy link

scmcca commented Dec 29, 2021

Is there a way to define this globally for all external links, instead of defining it directly in markdown every time?

@facelessuser
Copy link
Contributor

Is there a way to define this globally for all external links, instead of defining it directly in markdown every time?

Can you define what "this" refers to? Are you talking about converting all links to use target=_blank? The question seems a bit vague?

@scmcca
Copy link

scmcca commented Dec 29, 2021

@facelessuser Sorry about that.

My question is asking if there is a way to define once (perhaps in mkdocs.yml) the conversion of all links that lead to somewhere outside of the local website to use target=_blank (i.e., opening in a new tab) instead of defining target=_blank manually at every instance of an external link. Links that lead to somewhere within the site are okay to be left as default (i.e., not opening a new tab). My challenge is that I'm pulling content from external repositories, so updating the markdown directly to have target=_blank on external links is not a feasible option. I would either have to add target=_blank manually every time I need to pull the updated markdown files, or write a script that adds target=_blank at every external link. Does that make sense?

@facelessuser
Copy link
Contributor

This isn't really a theme thing. This could be done with a Python Markdown extension or a MkDocs plugin. I'm not certain at this time if such an extension or plugin already exists, but that is the way such things should be approached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug
Projects
None yet
Development

No branches or pull requests

6 participants