-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ddaf3e
commit be45c7e
Showing
7 changed files
with
109 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,91 @@ | ||
# Notebooks in markdown | ||
--- | ||
jupytext: | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
format_version: '0.8' | ||
jupytext_version: 1.4.1+dev | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
--- | ||
# Notebooks as Markdown | ||
|
||
MyST-NB also provides functionality for notebooks within markdown. This lets you | ||
include and control notebook-like behavior from with your markdown content. | ||
MyST-NB also provides functionality for writing notebooks in a text-based format, | ||
utilising the [MyST Markdown format](https://jupytext.readthedocs.io/en/latest/formats.html#myst-markdown) outlined in [jupytext](https://jupytext.readthedocs.io). | ||
These files have a 1-to-1 mapping with the notebook, so can be opened as notebooks | ||
in Jupyter Notebook and Jupyter Lab (with jupytext installed), and are also integrated | ||
directly into the {ref}`Execution and Caching <execute/cache>` machinery! | ||
|
||
The primary way to accomplish this is with the `{jupyter-execute}` directive. The content | ||
of this directive should be runnable code in Jupyter. For example, the following | ||
code: | ||
They are distinguished from standard Markdown files by adding this top matter to the first line of you file (or the relevant `kernelspec` for your code): | ||
|
||
```` | ||
```{jupyter-execute} | ||
```md | ||
--- | ||
jupytext: | ||
text_representation: | ||
format_name: myst | ||
kernelspec: | ||
display_name: Python 3 | ||
name: python3 | ||
--- | ||
``` | ||
|
||
```{tip} | ||
You can also create the file from an existing notebook: `jupytext notebook.ipynb --to myst` | ||
``` | ||
|
||
The following syntax can then be used to define a code cell: | ||
|
||
````md | ||
```{code-cell} ipython3 | ||
a = "This is some" | ||
b = "Python code!" | ||
print(f"{a} {b}") | ||
``` | ||
```` | ||
|
||
Yields the following: | ||
Yielding the following: | ||
|
||
```{jupyter-execute} | ||
```{code-cell} ipython3 | ||
a = "This is some" | ||
b = "Python code!" | ||
print(f"{a} {b}") | ||
``` | ||
|
||
Currently, this uses [Jupyter-Sphinx](https://jupyter-sphinx.readthedocs.io/) | ||
under the hood for execution and rendering. | ||
The same metadata tags can be used as you would in a normal notebook, | ||
for example those discussed in {ref}`use/hiding/code`: | ||
|
||
````md | ||
```{code-cell} ipython3 | ||
:tags: [hide_output] | ||
|
||
for i in range(20): | ||
print("Millhouse did not test cootie positive") | ||
``` | ||
```` | ||
|
||
Yields the following: | ||
|
||
```{code-cell} ipython3 | ||
:tags: [hide_output] | ||
for i in range(20): | ||
print("Millhouse did not test cootie positive") | ||
``` | ||
|
||
and `raises-exception` means our code will execute without halting the kernel: | ||
|
||
````md | ||
```{code-cell} ipython3 | ||
:tags: [raises-exception] | ||
|
||
raise ValueError("oopsie!") | ||
``` | ||
```` | ||
|
||
```{code-cell} ipython3 | ||
:tags: [raises-exception] | ||
raise ValueError("oopsie!") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ kernelspec: | |
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
author: Chris | ||
--- | ||
|
||
# a title | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters