Skip to content

Commit cfd5b9e

Browse files
authored
📚👌‼️: Improve documentation and usability (#405)
This PR completely restructures the documentation and makes a number of key usability improvements: 1. Simplified top-matter for text-based notebooks The previous usage of a jupytext configuration will still work, e.g. ```yaml --- jupytext: text_representation: extension: .md format_name: myst format_version: '0.13' jupytext_version: 1.13.8 kernelspec: display_name: Python 3 language: python name: python3 --- ``` but now the following can also signify a text-based notebook: ```yaml --- file_format: mystnb kernelspec: name: python3 --- ``` Note `display_name` is no longer required to be specified, since it is added as the `name`, if missing. 2. The cell metadata key `render` is replaced with `mystnb`, to make it consistent with the notebook metadata key. For old notebooks using `render`, this will still be read and issue a deprecation warning 3. The `mystnb-quickstart` CLI command has been added, to create a template Sphinx + MyST-NB project
1 parent ba22f95 commit cfd5b9e

46 files changed

Lines changed: 1406 additions & 837 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/Makefile

Lines changed: 0 additions & 28 deletions
This file was deleted.

docs/authoring/basics.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
2+
(authoring/intro)=
3+
# The basics
4+
5+
## Default file formats
6+
7+
As well as writing in the Sphinx default format, [RestructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html) (`.rst`), loading `myst_nb` will also parse:
8+
9+
- Markdown files (`.md`)
10+
- Jupyter notebooks (`.ipynb`)
11+
- MyST-NB text-based notebooks (`.md` + top-matter)
12+
13+
## Custom file extensions
14+
15+
You can change which file extensions are parsed by MyST-NB using
16+
the [source_suffix](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-source_suffix) option in your `conf.py`, e.g.:
17+
18+
```python
19+
extensions = ["myst_nb"]
20+
source_suffix = {
21+
'.rst': 'restructuredtext',
22+
'.ipynb': 'myst-nb',
23+
'.myst': 'myst-nb',
24+
}
25+
```
26+
27+
## Other notebook formats
28+
29+
See the [](write/custom_formats) section, for how to integrate other Notebook formats into your build, and integration with [jupytext](https://github.com/mwouts/jupytext).
30+
31+
## MyST Markdown
32+
33+
For all file formats, Markdown authoring is the backbone of MyST-NB.
34+
By default, the MyST flavour of Markdown is enabled,
35+
which extends [CommonMark](https://commonmark.org/) with RST inspired syntaxes to provide the additional functionality required for technical writing.
36+
37+
In particular MyST adds targets, roles and directives syntax, allowing you to utilise all available Docutils/Sphinx features:
38+
39+
::::{grid} 2
40+
:gutter: 1
41+
42+
:::{grid-item-card} RestructuredText
43+
44+
```
45+
.. _target:
46+
Header
47+
------
48+
49+
:role-name:`content`
50+
51+
.. directive-name:: argument
52+
:parameter: value
53+
54+
content
55+
```
56+
:::
57+
58+
:::{grid-item-card} MyST Markdown
59+
60+
````
61+
(target)=
62+
# Header
63+
64+
{role-name}`content`
65+
66+
```{directive-name} argument
67+
:parameter: value
68+
69+
content
70+
```
71+
````
72+
:::
73+
::::
74+
75+
:::{seealso}
76+
See the [](authoring/jupyter-notebooks) section, for more details on how to author Jupyter notebooks.
77+
:::
78+
79+
## Text-based notebooks
80+
81+
MyST-NB text-based notebooks are a special format for storing Jupyter notebooks in a text file.
82+
They map directly to a Notebook file, without directly storing the code execution outputs.
83+
84+
To designate a Markdown file as a text-based notebook, add the following top-matter to the start of the file:
85+
86+
```yaml
87+
---
88+
file_format: mystnb
89+
kernelspec:
90+
name: python3
91+
---
92+
```
93+
94+
The `kernelspec.name` should relate to a [Jupyter kernel](https://github.com/jupyter/jupyter/wiki/Jupyter-kernels) installed in your environment.
95+
96+
Code cells are then designated by the `code-cell` directive:
97+
98+
````markdown
99+
```{code-cell}
100+
:tags: [my-tag]
101+
102+
print("Hello world!")
103+
```
104+
````
105+
106+
and Markdown can be split into cells by the `+++` break syntax:
107+
108+
```markdown
109+
Markdown cell 1
110+
111+
+++ {"tags": ["my-tag"]}
112+
113+
Markdown cell 2, with metadata tags
114+
```
115+
116+
:::{seealso}
117+
See the [](authoring/text-notebooks) section, for more details on text-based notebooks, and integration with [jupytext](https://jupytext.readthedocs.io).
118+
:::
119+
120+
## Configuration
121+
122+
...
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ jupyter:
88
name: python3
99
---
1010

11-
(examples/custom_formats)=
12-
# Custom Notebook Formats
11+
(write/custom_formats)=
12+
13+
# Custom Formats
1314

1415
You can designate additional file types to be converted to Notebooks, and then executed / parsed in the same manner as regular Notebooks, by adding the following configuration to your `conf.py`:
1516

@@ -33,7 +34,7 @@ nb_custom_formats = {
3334

3435
:::{important}
3536

36-
By default, Markdown cells in the Notebook will be parsed using the same MyST parser configuration as for other Markdown files ([see available configuration options](config/reference)).
37+
By default, Markdown cells in the Notebook will be parsed using the same MyST parser configuration as for other Markdown files ([see available configuration options](config/intro)).
3738

3839
But, if this is incompatible with your file format, then you can specify for the Markdown to be parsed as **strictly CommonMark**, using a third argument:
3940

docs/authoring/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Authoring
2+
3+
Create content in one or more formats.
4+
5+
```{toctree}
6+
:maxdepth: 1
7+
8+
basics
9+
jupyter-notebooks
10+
text-notebooks
11+
custom-formats
12+
```
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
---
2-
jupytext:
3-
text_representation:
4-
extension: .md
5-
format_name: myst
6-
format_version: '0.8'
7-
jupytext_version: '1.4.1'
2+
file_format: mystnb
83
kernelspec:
9-
display_name: Python 3
10-
language: python
114
name: python3
125
---
136

14-
# An example Jupyter Notebook
7+
(authoring/jupyter-notebooks)=
8+
# Jupyter Notebooks
159

1610
This notebook is a demonstration of directly-parsing Jupyter Notebooks into
1711
Sphinx using the MyST parser.[^download]
1812

19-
[^download]: This notebook can be downloaded as
20-
**{nb-download}`basic.ipynb`** and {download}`basic.md`
13+
[^download]: This notebook can be downloaded as **{nb-download}`jupyter-notebooks.ipynb`** and {download}`jupyter-notebooks.md`
2114

2215
## Markdown
2316

17+
:::{seealso}
18+
For more information about what you can write with MyST Markdown, see the
19+
[MyST Parser syntax guide](myst:syntax/syntax).
20+
:::
2421

2522
### Configuration
2623

@@ -40,6 +37,11 @@ myst_enable_extensions = [
4037
myst_url_schemes = ("http", "https", "mailto")
4138
```
4239

40+
:::{note}
41+
Loading the `myst_nb` extension also activates the [`myst_parser`](myst:index) extension, for enabling the MyST flavour of Markdown.
42+
It is not required to add this explicitly in the list of `extensions`.
43+
:::
44+
4345
### Syntax
4446

4547
As you can see, markdown is parsed as expected. Embedding images should work as expected.

0 commit comments

Comments
 (0)