Single file of a multi-files gist on Medium.com

Does anyone know a way to include a single file of a multi-file gist into a medium post?

I've tried, without luck, the solutions proposed here:

  • How do I embed a single file from a GitHub gist with the new gist interface?
  • Yes, we get the gist

Thanks, M.


Solution 1:

2020 - It is possible! 🎊🎉

There is a way for that without using <script>, but it's kind of tricky:

⚠️ The order matters!

  1. Copy the (multi-file) gist path. e.g.:
https://gist.github.com/MojtabaHs/91e34fd0e987fe7ce801936dc6ece0e8

  1. Paste it somewhere else than the Medium article. Like an online textbox:

Demo

⚠️ Do not hit search or return button


  1. 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?


  1. 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.

Solution 2:

Nov 2017: this is still not possible.
The Medium API for posts refers to "Accepted markup for Medium’s Publishing API" and the markdown syntax.
None of them includes a <script>, needed to include a Gist single file

<script src="https://gist.github.com/<id>.js?file=afile" type="text/javascript" />

The only workaround is to generate the article content, included the gist file, and publish the built text with everything in it.
If the Gist changes though, that means the article has to be updated.

Phelipe Rocha mentions in the comments the article "Dealing with Code on Medium" from Egon Elbre

The least frustrating approach I’ve found was using code screenshots. Obviously, this is very annoying for readers.

I would add: combining a screenshot with an HTML link referencing the gist file might be an acceptable workaround (notwithstanding the gist changes, which would mean updating the screenshots).