How do I embed a single file from a GitHub gist with the new gist interface?
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>
Medium
For those who want to use it on the medium, Medium does not support and does not query parameters in the URL when you add it after the paste of the URL. So just follow these 4 steps IN THE ORDER.
So:
⚠️ Order matters!
- Copy the (multi-file) gist path. e.g.:
https://gist.github.com/MojtabaHs/91e34fd0e987fe7ce801936dc6ece0e8
- Paste it somewhere else than the Medium article that not preserves the rich data of the text. Like an online textbox for example:
⚠️ Do not hit search or return button
- Append the query param for the file to the URL. e.g:
https://gist.github.com/MojtabaHs/91e34fd0e987fe7ce801936dc6ece0e8?file=Interface.swift
Note that ?file=Interface.swift
at the end of the URL, right?
- Copy and paste it in the article and see the magic
An article using this method:
Implement Custom Activity Indicator With The SwiftUI
The MOST Important note that MUST be considered:
⚠️ Note that you MUST copy an unformatted plain text in the medium and MUST NOT edit the URL after pasting it in the Medium! You can copy the link in an online textbox like google.com and after appending the query, copy it back and paste it in the Medium.