How embed code snippet into conversation? - github

I can't figure out how embed code snippets into my conversation, like this:
From google I found some tutorials like:
Introducing Embedded Code Snippets / Embedded Code Snippets / Creating a Permanent Link to a Code Snippet (they are all github official help documents)
and I tried follow them, but instead of showing nice box it shows as:
Did I miss something - maybe I have to enable it somewhere or is it available only for github Pro and Staff versions ?

I found the answer:
Permanent link will render as a code snippet only in the repository it originated in.
In other repositories, the permalink code snippet will render as a URL.

Related

What is a comment thread in the vs code api?

In the Api docs of VS Code there is a concept of Comment Thread under the workspace. Is there an example of this? What are these threads? Can developers have discussions on comments? Where are these comments saved?
https://code.visualstudio.com/api/references/vscode-api#CommentThread
I tried googling and the closest I came to an example was this issue thread.
https://github.com/microsoft/vscode/issues/71171
How could I open this comment discussions in my workspace? Sorry if this is a newbie VS Code question - just recently converted.
How could I open this comment discussions in my workspace? Sorry if this is a newbie VS Code question - just recently converted.
This is an API used by extension developers. This is relevant to you if you want to create your own VS Code extension, and you need a way to display comments/discussions inside the code.
See https://github.com/microsoft/vscode-extension-samples/tree/main/comment-sample for an example + screencast. You first need to create a CommentController. The CommentController allows you to create a CommentThread. A CommentThread is a list of comments. Each Comment will have a body (text or markdown), author, date, etc.
A common use-case of this API is to show code review comments. In particular, this is used by the GitHub Pull Requests extension, but you could imagine other use-cases for showing comments discussions inside a file.
Where are these comments saved?
This API deals only with the UI. You decide where the discussions are stored (e.g. make request to a service, or store them on disk). Once you have the data inside your extension, use this API to render them.

Mermaid syntax error on trying render a diagram on Github .md file

I've followed this MermaId tutorial but when I try put into my .md file on Github an error is raised:
This works perfectely on Live editor.
Code:
```mermaid
sequenceDiagram
autonumber
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
```
Someone can help me find my error on try write it on Github
Currently, I struggle on a similar problem.
With GitHub, do you mean GitHub pages?
Could you find a solution to it?
Personally, I have a setup with Jekyll. Here is my question on how to setup mermaid correctly for jekyll.
Interestingly, I just posted your mermaid into my jekyll page and the result is:
If I put it into <div> tags with class mermaid. Setup I used was this.
And if I use the jekyll spaceship-plugin, ist renders to:
I guess, that this what it should like. Am I right?
Therefore, so far, for me mermaid works based on the spaceship plugin, but not by "natively" referencing the mermaid JavaScript. I do not know if spaceship will work with GitHub pages, however, definitely within GitHub pages (which is based on Jekyll), you may also add plugins. See documentation for further details.

Github Gist Ghost Injection, Single Snipplet

I have my blog made by 'Ghost', and I'm trying to inject Github Gist in my post using the javascript github provides.
However, I usually keep a lot code snipplets in a single gist.
https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b
Like the link above, this gist contains 2 code snipplets.
However, I want to post only 1 of the 2 snipplets.
By the Github guide, normally you inject your gist like
<script src="https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b.js"></script>
However, by this method, both the 2 snipplets show on my blog.
I tried like,
However, this doesn't showed snipplets at all.
Anyone knows a solution for this?
How about this? You can use a query parameter of file= for the URL.
When you want to embed 2.cpp from the gist, you can use a following code.
<script src="https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b.js?file=2.cpp"></script>
When you want to embed temp.cpp from the gist, you can use a following code.
<script src="https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b.js?file=temp.cpp"></script>
If I misunderstand your question, I'm sorry.

Can I embed source files from GitHub on my web page other than Gists?

Context
You can create a Gist on GitHub and embed it on your web page: embedding Gists.
This is an example of a randomly chosen Gist: tap.groovy.
Question
Is embedding also possible with other code files from GitHub, for example with this randomly chosen C# file ICommand.cs which is not a Gist?
You can try https://emgithub.com, which does exactly what you want.
To embed the example file ICommand.cs in your question, you can just add "em" before "github.com" in the address bar, then press Enter.
Then you can get a script tag like this:
<script src="https://emgithub.com/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fdotnet%2Fcorefx%2Fblob%2Fmaster%2Fsrc%2FSystem.ObjectModel%2Fsrc%2FSystem%2FWindows%2FInput%2FICommand.cs&style=default&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showCopy=on"></script>
Note if you simply click Run code snippet in StackOverflow, the copying button at top right corner may not work. Running it outside SO would work fine.
Unlike other websites that do similar work, EmGithub.com is a static site hosted on Github Pages. Fetching target files and highlighting are done on your browser.
Disclosure: I'm the developer of it :)
You can use https://gist-it.appspot.com/:
<script src="http://gist-it.appspot.com/https://github.com/dotnet/corefx/blob/master/src/System.ObjectModel/src/System/Windows/Input/ICommand.cs"></script>
There's a standard for embedding content from one website in another via a URL, called oEmbed. Unfortunately, GitHub is not a oEmbed provider, i.e. it doesn't support oEmbed for its URLs.
I found a proxy service, Oembed Proxy for GitHub,
which adds oEmbed support for GitHub's code URLs. You pass a GitHub URL as a parameter to the proxy's URL and a resulting URL can be be pasted in another website, assuming that website supports embedding oEmbed links.
Another obstacle is that not every website supports embedding oEmbed URLs. According to the proxy's documentation, notion is one website that supports them. I did some research and looks like it should be possible to add oEmbed support to e.g. wordpress or jekyll.
This answer provides a very limited solution, due to small adoption of oEmbed. I thought it would be worth to spread the word nonetheless.
Another possible service is https://github.com/finom/github-embed. It seems to be unmainted by now for about 2 years, but gist-it seems to be unmaintained for even 6 years. I've tried neither, though.
You can use gistYard
<iframe src="https://gistyard.piyushdev.xyz/emd.html?lang=&from=0&to=&code=https://raw.githubusercontent.com/dotnet/corefx/master/src/System.ObjectModel/src/System/Windows/Input/ICommand.cs&edit=true&dm=off" width="100%" height="330" frameborder="0"></iframe>
It provides features like changing theme , cutting code directly from raw , edit mode , custom styling and others.

Markdown - code as link in GitHub readme

I wanted to create inline span of code that links to other page.
I want to use
`MongoCollection`
and
[MongoCollection](#http://php.net/manual/en/class.mongocollection.php)
together to make a link on a code element.
I tried
[`MongoCollection`](#http://php.net/manual/en/class.mongocollection.php)
and
`[MongoCollection](#http://php.net/manual/en/class.mongocollection.php)`
Both didn't work.
Is there any way to do that?
Could you explain a bit more about what you mean by inline span of code? This works in Github and links the MongoCollection link to the Mongo Collection php manual page.
[MongoCollection](http://php.net/manual/en/class.mongocollection.php)
Is that what you are looking for?