Vscode-markdown: Request: Open external links in new tab (option)

Created on 26 Sep 2020  ·  2Comments  ·  Source: yzhang-gh/vscode-markdown

Hi,

Thanks for sharing this extension (and your support on the upstream request)!

Feature Request

After printing to HTML, I was surprised all the links opened in the same tab. Could I request an option to choose if external links open in a new tab instead with target="_blank"?

Perhaps, named something like "markdown.extension.print.linkTarget": "_blank" with other available options listed here.

Thank you.

Additional Background

There are plenty of posts on Stack Overflow asking how to implement a feature that isn't natively available in Markdown. In general, the main takeaway is to use an HTML snippet as a workaround. For example:

<a href="http://example.com/" target="_blank">Hello, world!</a>

There are also some some mentions of using a syntax specific to kramdown Markdown-parser; which doesn't help with VSCode.

[Hello, world!](http://example.com/){:target="_blank"}

Finally, there's even a mention of a GatsbyJS plugin which has complete configurability of links. Again, this is of no help with VSCode but provides general context, such as the addition of rel="noreferrer noopener".

plugins: [
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        {
          resolve: 'gatsby-remark-external-links',
          options: {
            target: '_blank',
            rel: 'noopener noreferrer',
          }
        }
      ]
    }
  }
];
Help wanted Markdown dialect

Most helpful comment

Thanks for the feedback.

There is a markdown-it plugin markdown-it-link-attributes. I would suggest someone make a standalone VSCode extension based on it. (Actually it is very easy, just a few lines of code.)

All 2 comments

Thanks for the feedback.

There is a markdown-it plugin markdown-it-link-attributes. I would suggest someone make a standalone VSCode extension based on it. (Actually it is very easy, just a few lines of code.)

Thanks for the response, @yzhang-gh, appreciate it.

Given the simplicity of adding target="_blank" in HTML, I was hopeful there might be an equivalent custom-option in Markdown. While you've identified that _there is_, but I'm not sure how to implement it at the moment.

Was this page helpful?
0 / 5 - 0 ratings