Replies: 9 comments 15 replies
-
|
in general you can use back ticks (they are on the same key as the tilde ~ on most qwerty keyboards) - this works anywhere that renders markup. example
also, for code blocks you can use three: |
Beta Was this translation helpful? Give feedback.
-
|
Yes I did misunderstand - and your right, it makes it sound like it should work in the same repo - which it looks like you are. Maybe it works on 'comments' but not issues... |
Beta Was this translation helpful? Give feedback.
-
|
It looks like documented feature that doesn't work at all. Or just the screenshot is misleading, something like this was working, I've seen code snippets in issues. |
Beta Was this translation helpful? Give feedback.
-
|
To include a code snippet in a GitHub issue comment:
Right now, GitHub sometimes does not render permalinks as embedded code in comments. In that case, use the code formatting methods above or attach an image. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
|
There is another blocker for displaying the code lines: if you have enabled git blame in the code view and then copy the link to one or more lines and paste it into an issue you don't get the code vierw. This is because the link doesn't start like
but
If you manually change the |
Beta Was this translation helpful? Give feedback.
-
|
On GitHub, simply pasting a permalink to a line range does not automatically render a fancy embedded code snippet in issue comments. The “rich code preview” (the boxed snippet view) only works in certain places like pull request descriptions, PR review comments, or when using the “Insert a suggestion” feature. Regular issue comments don’t auto-expand permalinks into code previews. So you didn’t necessarily do anything wrong it’s just a limitation of where GitHub supports snippet embedding. If you want to include code in an issue comment, the reliable way is to use Markdown code fences: ```language // your code here ``` Example: ```cpp int add(int a, int b) { return a + b; } ```
If you want to reference a specific line in a file, you can still paste the permalink, but it will stay as a normal link. |
Beta Was this translation helpful? Give feedback.
-
|
To include a code snippet, you can use triple backticks (```) before and after your code. For example: console.log("Hello World");This will format it properly with syntax highlighting. |
Beta Was this translation helpful? Give feedback.
-
|
GitHub uses Markdown, so adding code is just formatting — no special buttons needed. Inline code (for small things)Use a single backtick Example:
It shows up like: Good for commands, file names, variables, flags, etc. Code block (the one you usually want)Use three backticks before and after the code. ``` your code here ``` With syntax highlighting (much nicer)Add the language name right after the first three backticks. ```python
def hello():
print("Hello world")
```
GitHub will color it automatically. Common ones:
Pro tip (people miss this)If your code itself contains backticks, wrap it with four backticks outside: ```` ``` actual code that has backticks ``` ```` That’s it — GitHub comments, issues, PRs, discussions all follow the same rules. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, When you paste a permalink to a specific range of code, GitHub only renders it as a rich code snippet preview in certain contexts. In many cases (including some issues and discussions), the link will remain a normal URL instead of expanding automatically. A few things to check: Make sure the link is a permalink to a specific commit, not to a branch (e.g., main). You can generate a true permalink by pressing y while viewing the file on GitHub. Ensure the link includes the line range (for example: #L10-L25). The preview only works when the link is pasted on its own line (not embedded inside text or backticks). If all of the above are correct and it still doesn’t expand, it may simply be a limitation of the context where you’re posting. GitHub does not always render rich previews inside issues or certain discussion views. |
Beta Was this translation helpful? Give feedback.



Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Body
According to this doc, just pasting the permalink of the range of codes would be fine. However, when I tried that in this issue, the link was shown as is instead of showing a fancy code snippet. What did I do wrong?
Beta Was this translation helpful? Give feedback.
All reactions