Skip to content

Instantly share code, notes, and snippets.

@matsen
Forked from iamlemec/nb2md
Last active February 22, 2021 21:44
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matsen/37521f504a14aede644d to your computer and use it in GitHub Desktop.
Save matsen/37521f504a14aede644d to your computer and use it in GitHub Desktop.
Markdown diffs for jupyter notebooks.

For sane jupyter notebook diffs

  • Install the nbconvert package, though you probably already have it if you are using jupyter.
  • Put the nb2md script below in your path and make executable
  • Add the following to your .gitattributes file, which can be in your home directory (use nb2md for all projects) or in the root of your project:
*.ipynb diff=nb2md
  • Run
git config --global diff.nb2md.textconv nb2md

to use nb2md for all projects, or add the following to your project's .git/config

[diff "nb2md"]
        textconv = nb2md
  • 😊
#!/bin/sh
jupyter nbconvert --to markdown $1 --stdout --log-level=0
@michaelaye
Copy link

this seems to fail with spaces in filenames, right?

@apinstein
Copy link

@michaelaye yes it fails with spaces in filenames, if you do "$1" instead, it works perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment