76

I want to have links inside my code blocks using GitHub flavored markdown.

```cpp
void Click ([Keycode](#keycode) key) const
```

Unfortunately, it renders that as code, anyway to make it a link instead?

0

5 Answers 5

48

If its a short piece of code this should do the trick:

[`this is code`](https://this_is_url/)

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

Comments

26

As far as I know, the current instance of GitHub Flavored Markdown doesn't support this.

The all block is rendered with <div class="highlight highlight-html"><pre>... </pre></div>, meaning your markdown link is not interpreted.

It would be best to place that link just before the code section (unless said section has dozens of similar links in your code).

3 Comments

highlight-html can vary depending on the detected language, but the point remain: everything is wrapped in pre, which means any code (markdown or html) won't be interpreted.
Yeah I'm pretty sure you're right. For me it was more of a design issue but I think I found a way around it (see my answer).
Thanks @Dave. Your answer achieves a good workaround for this issue.
21

As suggested by VonC, it might not be possible with the current version of GitHub Flavored Markdown. That being said, I did find a way around it which suits my requirements. By using tags like <big>, <pre> and <b> I'm able to simulate syntax highlighting and get the effect I'm looking for. Too bad I can't add my own color though.

<big><pre>
**void** Click ([**Keycode**](#keycode) key) **const**
</pre></big>

4 Comments

+1, but your original question was about the possibility to include a link (something on which you can click), not just about the visual aspect. So my answer stands.
I'm not disputing your answer, simply offering an alternative.
You don't need the <big> tags. Just precede the <pre> tag with a space.
But <big> more closely presents like a code block does with ``` so I'm glad he recommended it.
17

You can do this using HTML in markdown, yes, even on Github:

<pre>
<a href="my-url">Something</a>
</pre>

1 Comment

A concise version of this (in markdown) could be <pre> [Something][] </pre>. See reference links in daringfireball.net/projects/markdown/syntax#link
5

This makes the trick.

I use it on my GitHub profile page to put links inside code blocks.

<pre>
 <code>
  <a href="https://github.com/gmarciani">gmarciani</a>
 </code>
</pre>

1 Comment

Giacomo does that work for a ```c++ code block ?

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.