Github Gist Ghost Injection, Single Snipplet - github

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.

Related

How embed code snippet into conversation?

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.

How to embed a Gist within a GitHub issue comment?

I have a Gist that I would like to embed within a GitHub issue. I have tried pasting the "Embed" <script> markup shown on the Gist page, which simply adds the escaped HTML to the issue comment.
This seems a rather obvious feature to not be supported. What am I missing?
Because embedding requires a <script> tag which gets sanitized and removed to prevent abuse this probably won't ever work in GitHub Issues.

How to quote code in a Mardkown GitHub Gist

In a markdown file in a Gist, how do you quote some lines of code that are in a GitHub project?
If I was writing a Gist to try and explain how something works, I might have a block of text, then quote some code. I don't want to cut and paste the code in, I just want to quote some lines of code in a GitHub project. I am sure I have seen this done, but can't find an explanation of how to do it.
For example:
This algorithm makes use of Dijkstra's topological sort algorithm:
100: Result myFancyPantsAlgorithm(Blah blah) {
101: youGetTheIdea();
102: }
It is not possible to embed GitHub code snippets from Repositories.
What you might have seen is having a gist embedded in a "normal" website which is possible because GitHub provides a script to embed gists.
The script tag is (un)fortunately not whitelisted to be used in GitHub Flavored Markdown, so it is not possible to embed a gist in markdown.
A way to get around this would be to set a gh-page up, where you are able to embed a Gist as this SO-question shows. But then you're still not referencing to any live codebase.
So the answer to your question is: this is not possible, wether by embedding code from a repository nor by taking a detour via using gists.

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?