Markdown code snippets not rendering after uploading notebook to GitHub

In my Jupyter Notebook,
I’ve the following contents in the markdown cell

On running this same cell locally,
I get the result as expected
(sorry for not attaching the screenshot as I am a new user and I am not allowed to attach more than one attachement)

but when I uploaded this notebook to GitHub,
those code snippets for the bash were note rendered
which you can find it here :

So how do I resolve this ?

Version info :

Selected Jupyter core packages...

IPython          : 8.3.0
ipykernel        : 6.9.1
ipywidgets       : 7.6.5
jupyter_client   : 7.2.2
jupyter_core     : 4.10.0
jupyter_server   : 1.13.5
jupyterlab       : 3.3.2
nbclient         : 0.5.13
nbconvert        : 6.4.4
nbformat         : 5.3.0
notebook         : 6.4.11
qtconsole        : 5.3.0
traitlets        : 5.1.1

A lot of your issues are just being caused by trying to do things markdown is tricky about handling or not using enough whitespace. For example, you shouldn’t indent the code blocks. Markdown will do that for you and as you see it causes issues if you try to do it yourself. And about the whitespace, you need a new line below a heading and other text.

In fact, I note that when you get to what you have for the ### Install Docker Compose portion, things really go off the rails even in a live notebook.

Additionally, never rely on GitHub for accurate rendering of notebooks. I always tell people it is meant for nothing more than a quick preview. Always use the Jupyter provided nbviewer. nbviewer will render public notebooks that are on GitHub and has the ability to render many more features than GitHub and renders it more accurately. Plus, the interface that faces users from nbviewer is more palatable to those unfamiliar with GitHub and so it is best to share that. The URL for the nbviewer rendering is a simple variation on the GitHub URL. You can get the URL by pasting the GitHub URL here.


To illustrate all of this, you can find the code block from what you included in your screenshot MODIFIED TO FIX THE ISSUES here.

Here it is rendered via nbviewer.

Note how it is very different than you see at GitHub’s quick preview

Even the nbviewer rendering for the same markdown in the notebook is not as nice as the rendering in active JupyterLab.

Or rendering within the active classic notebook.

But the nbviewer rendering is much closer.


Keep in mind that the free service at nbviewer doesn’t update as fast a GitHub directly though, and because of that you need to be patient. Once you render it once at nbviewer, it has gotten to the point it can take hours before nbviewer will pick up and render any additional changes and edits you post at GitHub. As reported here even the trigger to workaround this isn’t quite working well at present. I just tested it and I could get an update using it, but then if I updated again, the newer update didn’t show after many minutes. (It’s not browser caching causing this because opening a different browser and using the two variations of the the URL, one with ?flush_cache=true and one without, yielded the same outdated two versions.)
For NOW this workaround of using raw link that has commit sha as ref works when you need to see how nbviewer will render the most up to date notebook code. For using notebooks from gists, this means going to the current GitHub page for it and pressing the raw button and using that URL in the form at nbviewer. For a standard GitHub repo, this means going to the listing of all the commits by pressing ‘History’ on the right side of the main page, then from the list selecting the last commit tag stub in blue on the right, then from that next page selecting the ‘Browse files’ button in the upper right, then while browsing the files from that commit, navigating to the notebook you want and collecting the ‘raw’ URL to use at nbviewer. However, as noted by the person who posted this isn’t really “a practical solution”.

2 Likes

Thanks a lot @fomightez
I was currently doing MLOps bootcamp and I wanted to have central repository where people can just have a look at my notes for the same on the Github itself as later I might add few more things with the actual code
So just for now I am thinking about using GitHub markdown but thanks for introducing me to the nbviewer I’ll surely use it later for sharing my work
Thank you