94

I have a Markdown file in which I use a link multiple times, for example:

This [website][an_awesome_website_link] is awesome.

You will never use anything else than this [website][an_awesome_website_link].

[an_awesome_website_link]: https://stackoverflow.com

Formatted, it looks like:

This website is awesome.

You will never use anything else than this website.


I want to display the link URL of [an_awesome_website_link] without having to write again the said URL.

For example, I want to have this, and write the URL of Stack Overflow only one time in my Markdown file:

This website (https://stackoverflow.com).

You will never use anything else than this website.

Check out https://stackoverflow.com for more fun.

Is it possible? How?

5
  • 3
    The question already contains the answer... Commented Dec 27, 2016 at 12:37
  • what markdown processor are you using? Commented Dec 27, 2016 at 12:40
  • 1
    @Jonasw Where ? Commented Dec 27, 2016 at 12:40
  • @scoa GitLab Flavored Markdown Commented Dec 27, 2016 at 12:42
  • 2
    @Kadriles there is no standard-markdown (if there was such a thing) way to do this. I take it you're writing on a gitlab service, so the processing is done by the server and you have no control over it? Then, your only option seems to be to use a preprocessor (which could be using pandoc -t markdown with a custom filter). Commented Dec 27, 2016 at 12:47

3 Answers 3

135

In short, it's not possible without some sort of nonstandard extension or macro.

There are three kinds of links in Markdown.

  1. Standard links in which both the label and URL are defined together:

     [label](http://example.com)
    
  2. Reference links, which can be in one of two forms:

     [label][key] or [key]
    
     [key]: http://example.com
    
  3. Automatic Links, where the label is the URL:

     <http://example.com>
    

    While some implementations do not require the angle brackets, it is best to include them so that is works across all implementations.

However, there isn’t any facility to make reference to a reference link and have it display the URL instead of the label. Therefore, the most minimal way to generate your desired output would be with this Markdown input:

This [website (https://stackoverflow.com)][website] is awesome.

You will never use anything else than this [website].

Check out <https://stackoverflow.com> for more fun.

[website]: https://stackoverflow.com

That said, some Markdown parsers have extension APIs, and you could conceivably write an extension/plugin/macro which would give you the behavior you want. However, that would be nonstandard and would not work anywhere else, except with your locally modified parser. As you indicate, you are using a third-party hosting service, and then that is not likely to be an option for you.

Sign up to request clarification or add additional context in comments.

3 Comments

#3 is what I've been looking for - thank you! It's not documented well, at least where I looked.
@elBradford Automatic Links are documented in the original rules here: daringfireball.net/projects/markdown/syntax#autolink. That is the first (and usually only) place I go for Markdown syntax documentation.
Thanks! I used that resource, I just didn't look in the 'Miscellaneous' section, I expected it to be in the 'Links' section.
11

You don't have to use the second set of square brackets in reference links. You can use the linktext as identifier.

This [website] is awesome.

You will never use anything else than this [website].

Check out [https://stackoverflow.com][website] for more fun.

[website]: https://stackoverflow.com

will lead to.

This website is awesome.

You will never use anything else than this website.

Check out https://stackoverflow.com for more fun.

In my humble opinion, it is not possible to get the URL of an link as text, so you have to write "https://stackoverflow.com" a second time as linktext. But you can reduce the second bracket.

Comments

6

Markdown Links

Here are some examples of ways to write links in Markdown.

Examples

[Link][1]
[Another Link][2]
![Picture Me Link][3]
<https://hey-look-im-a-link.link/>

~~Some text~~

[1]: <https://somelink.domain/> "This text right here is fantastic because when you scroll over the link now it says everything that I wrote in this paragraph."
[2]: <https://im-another-link.com/> "I'm another link after the first link"
[3]: <https://upload.wikimedia.org/wikipedia/commons/a/ad/Vice_Kings_icon_%28small%29.png> "Stack Overflow won't let me post a picture."
Some Code [^1]
import sys
import os
import easygui

def resource_path(relative_path):
    base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
    return os.path.join(base_path, relative_path)

Examples in action

Link

Another Link

Picture Me Link

https://stackoverflow.com/

The End

Without the ability to show pictures, it's difficult to show you how nesting can make for some very interesting icons. I can show you a footnote to this module.

[^1]: Here’s a link to some code

3 Comments

I'm afraid I don't "get" the examples: neither do they get displayed illuminatingly with Firefox(110) or Opera(30), nor do I see in the markdown what they shall shine a light on.
You don't just put Markdown into a web page and have a web browser automatically interpret it. There has to be either a server side renderer that converts the Markdown into HTML, or a client side renderer that reads the Markdown in some local JavaScript and updates the DOM. Regardless, I think the OP's actual question has been misunderstood here.
Re "Without the ability to show pictures": That should be possible by now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.