1

GitHub can directly render Jupyter notebooks properly. For example, this page renders very nicely.

However, this page, or this page, do not. The code lines are all jumbled together without the proper line breaks.

The second one, for example, has a cell rendered thus:

enter image description here

Looking at their code (respectively here and here), they seem correct, and the code lines are properly finished with \n.

What explains the incorrect rendering?

5
  • 1
    This has already been covered here in 'On GitHub, Jupyter notebook code (in cell) wrongly displayed as a long string instead of separate lines' and here in 'End of line disappears on GitHub in Jupyter notebooks', and also a bit buried as a component of here. Concisely, you should in general always be using nbviewer, the Jupyter-provided solution for viewing notebooks. It pre-dated the initially very limited GitHub rendering and remains much more ... Commented Feb 13, 2024 at 13:37
  • 1
    <continued> full-featured and rich than the still limited abilities of the quick preview for developers provided by GitHub. You can point nbviewer at anything accessible on the internet. It has much less cruft around it and remains a better choice for sharing with non-developer stakeholders. nbsanity was proposed as better than it for mobile rendering, yet nbviewer works on mobile devices, too. Commented Feb 13, 2024 at 13:39
  • 1
    You examples looking fine at nbviewer: #1 here and #2 here. You'll note upon examination that the URLs for the GitHub-hosted pages follow a standard pattern so that you can skip entering the source URLs in the form at the main nbviewer page if you prefer. Commented Feb 13, 2024 at 15:30
  • Thanks. What is the best way you recommend to redirect people looking at the file on GitHub to nbviewer? Seems like adding the nbviewer link to the top of the notebook is the easiest even though not ideal. Commented Feb 13, 2024 at 18:09
  • 1
    My best advice is to share the nbviewer-based link with others and use it in your documentation. You can put a badge at the top like is commonly done on the of READMEs, too. See here. In the past when GitHub would readily acknowledge their limited rendering as they wouldn't try to even render anything over 100kb, they encouraged nbviewer use with a link to it there. That insured new users learned about nbviewer soon in their journey. Alas, it isn't the current situation. Commented Feb 13, 2024 at 18:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.