How To Add Source Code To Medium

Hi guys! I am going to try to explain how to add source code to medium that I need to use often and you probably need as well.

Photo by Andrew Neel on Unsplash

To do that I am going to use Github Gist. First of all let’s login our account and click the “Your gists”.

Gist is actually a git repository. You can store your source code here and share easily with links. So we are going to use those links to add our source codes to Medium. Let’s click to + symbol to add a new gist.

Here, to top of the screen we are going to write explanation of our gist.

Right after that we are going to add our source code name with it’s extension. Extension helps gist to identify our source code and will be colored according to that. Otherwise it will stays normal text file.

And finally we are going to write our source code.

After all we need to click “Create public gist” to create our gist, and embed to our Medium article.

We need to copy link to our gist. So we need to click the button that I highlighted with blue square and paste our link and press enter. After that we have successfully add our source code to Medium. With this method your source codes will be more readable if you compare with paste as normal text.

There is another key point with this method, let’s assume that you have added same source code to different articles and after some time you found a bug in it! With this method you do not need to change every article one by one. Since your articles are referencing to your gist, it will be enough for you to just change gist and ta-da! Every article you have referenced to your gist will be updated.

If you want you can watch the video of this article that is made by me.

Thank you for your time! Happy coding!

Sweden-based full-time developer, and lifelong learner. Loves to learn and experience. Motto: Stay Hungry, Stay Foolish | @anilemrah_