How do I embed a single file from a GitHub gist with the new gist interface?

GithubGist

Github Problem Overview


The new GitHub Gist interface has one embed snippet for the entire gist which embeds all files in the gist. The old interface had embed code for each file in the gist. Anyone know if there's a trick to embed a single file?

Github Solutions


Solution 1 - Github

Take the gist URL from the left-hand side and after the .js add a query string like ?file=myFile.blah, e.g.

<script src="https://gist.github.com/4505639.js?file=macroBuild.scala" type="text/javascript"></script>

Solution 2 - Github

Medium

For those who want to use it on the medium, Medium does not support

Solution 3 - Github

GitHub provides this same information here on their site. As others have said the official way is to attach ?file=name-of-file.ext to the end of the embed code's URL in order to only embed the file called name-of-file.ext (you can of course change the name to whatever the name of your file is). For example, if I wanted to embed the getGitContents.js file from the Gist at https://gist.github.com/westc/afac9258389fdfd2fdaf134ffaa0e923 I can use the following:

<script src="https://gist.github.com/westc/afac9258389fdfd2fdaf134ffaa0e923.js?file=getGitContents.js"></script>

In addition there is this YourJS blog post about this which allows you to enter your user name and see the embed codes for all of your gists and the underlying individual files.

Solution 4 - Github

Just for other people reference that might be looking into this.

If you are using Wordpress you may achieve this with the plugin oEmbed-gist and shortcode style:

[gist id="your-gist-id-here" file="your-file-name.js"].

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTravis ReederView Question on Stackoverflow
Solution 1 - GithubRoland KuhnView Answer on Stackoverflow
Solution 2 - GithubMojtaba HosseiniView Answer on Stackoverflow
Solution 3 - GithubMario MamaniView Answer on Stackoverflow
Solution 4 - GithubxnorcodeView Answer on Stackoverflow