0

How to convert ipynb file into txt or a markdown file where the JSON of the notebook file is wrapped in a code block?

I have a file ipynb which i want to convert into markdown or plain txt file. I create the file using vscode IDE. I don't see export to txt or md option. I have jupyter extension installed in vscode.

starball
  • 20,030
  • 7
  • 43
  • 238
  • You can export your file as html (https://stackoverflow.com/questions/69049818/how-to-export-jupyter-notebook-by-vscode-in-pdf-format-windows-10), then convert html to markdown with a HTML2MD converter – Sajjad Aemmi Jul 29 '23 at 09:29
  • 1
    @starball Yes I mean JSON wrapped in a code block – Nafi Rahim Jul 29 '23 at 09:57
  • With [Jupytext](https://jupytext.readthedocs.io/en/latest/formats-markdown.html#jupytext-markdown) you can convert it to markdown that can be run still like a notebook and converted back, see the last command in the first code block of [this section here in the documentation](https://jupytext.readthedocs.io/en/latest/using-cli.html#execute-notebook-cells). – Wayne Jul 29 '23 at 13:02

4 Answers4

1

You can view the textual JSON contents of Jupyter Notebooks in VS Code by using the View: Reopen Editor With Text Editor command in the command palette. If you want to create a markdown file containing that JSON wrapped in a code block, the just select all the JSON contents from the text view, then create a markdown file with a code block, and paste the contents of the file into that code block.

starball
  • 20,030
  • 7
  • 43
  • 238
0

Open your ipynb file with Text Editor in Linux or with Notepad in Windows. Then you will see a json like file. You can save it as txt file.

Sajjad Aemmi
  • 2,120
  • 3
  • 13
  • 25
0

In terminal, go to the directory with the notebook, and run

python -m notebook

It will open a page in a browser. Open your notebook. Under File in the top left, you can export your notebook into various formats.

Martin Benes
  • 265
  • 10
0

One better solution: Jupyter notebook has more options to export, also markdown and plain text.

enter image description here

Sajjad Aemmi
  • 2,120
  • 3
  • 13
  • 25
  • If you have installed Jupyter then you can do all the same exporting from the command line using `jupyter nbconvert` because under the hood that is what the Jupyter GUI that is shown in this answer is using. (Jupytext that I mentioned in my comment adds an easier interface to this sort of thing.) That way the OP is not needing to open a second IDE. The OP would though need Jupyter installed. (Related: The OP mentions using VSCode but not if they have installed the plugin/extension to work with Jupyter? I cannot speak to what if any conversion options it adds. Maybe someone knows?) – Wayne Jul 31 '23 at 12:25