|
| 1 | +(render/single-page)= |
| 2 | +# Single page builds |
| 3 | + |
| 4 | +```{versionadded} 0.14.0 |
| 5 | +``` |
| 6 | + |
| 7 | +Sphinx, and thus MyST-NB, is built on top of the [Docutils](https://docutils.sourceforge.io/docs/) package. |
| 8 | +MyST-NB offers a renderer, parser and CLI-interface for working directly with Docutils, independent of Sphinx, as described below. |
| 9 | + |
| 10 | +:::{note} |
| 11 | +Since these tools are independent of Sphinx, this means they cannot parse any Sphinx or Sphinx extensions specific roles or directives. |
| 12 | +::: |
| 13 | + |
| 14 | +On installing MyST-NB, the following CLI-commands are made available: |
| 15 | + |
| 16 | +- `mystnb-docutils-html`: converts notebooks to HTML |
| 17 | +- `mystnb-docutils-html5`: converts notebooks to HTML5 |
| 18 | +- `mystnb-docutils-latex`: converts notebooks to LaTeX |
| 19 | +- `mystnb-docutils-xml`: converts notebooks to docutils-native XML |
| 20 | +- `mystnb-docutils-pseudoxml`: converts notebooks to pseudo-XML (to visualise the AST structure) |
| 21 | + |
| 22 | +Each command can be piped stdin or take a file path as an argument: |
| 23 | + |
| 24 | +```console |
| 25 | +$ mystnb-docutils-html --help |
| 26 | +$ mystnb-docutils-html --nb-execution-mode="off" hello-world.ipynb |
| 27 | +$ mystnb-docutils-html --nb-read-as-md="yes" hello-world.md |
| 28 | +``` |
| 29 | + |
| 30 | +The commands are based on the [Docutils Front-End Tools](https://docutils.sourceforge.io/docs/user/tools.html), and so follow the same argument and options structure, included many of the MyST NB specific options detailed in the [](config/intro) section. |
| 31 | + |
| 32 | +:::{dropdown} Shared Docutils CLI Options |
| 33 | +```{docutils-cli-help} |
| 34 | +``` |
| 35 | +::: |
| 36 | + |
| 37 | +The CLI commands can also utilise the [`docutils.conf` configuration file](https://docutils.sourceforge.io/docs/user/config.html) to configure the behaviour of the CLI commands. For example: |
| 38 | + |
| 39 | +```ini |
| 40 | +# These entries affect all processing: |
| 41 | +[general] |
| 42 | +nb_execution_mode: off |
| 43 | + |
| 44 | +# These entries affect specific HTML output: |
| 45 | +[html writers] |
| 46 | +embed-stylesheet: no |
| 47 | + |
| 48 | +[html5 writer] |
| 49 | +stylesheet-dirs: path/to/html5_polyglot/ |
| 50 | +stylesheet-path: minimal.css, responsive.css |
| 51 | +``` |
| 52 | + |
| 53 | +You can also use the {py:class}`myst_nb.docutils_.Parser` class programmatically with the [Docutils publisher API](https://docutils.sourceforge.io/docs/api/publisher.html): |
| 54 | + |
| 55 | +```python |
| 56 | +from docutils.core import publish_string |
| 57 | +from nbformat import writes |
| 58 | +from nbformat.v4 import new_notebook |
| 59 | +from myst_nb.docutils_ import Parser |
| 60 | + |
| 61 | +source = writes(new_notebook()) |
| 62 | +output = publish_string( |
| 63 | + source=source, |
| 64 | + writer_name="html5", |
| 65 | + settings_overrides={ |
| 66 | + "nb_execution_mode": "off", |
| 67 | + "embed_stylesheet": False, |
| 68 | + }, |
| 69 | + parser=Parser(), |
| 70 | +) |
| 71 | +``` |
| 72 | + |
| 73 | +Finally, you can include MyST Markdown files within a RestructuredText file, using the [`include` directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#include): |
| 74 | + |
| 75 | +```rst |
| 76 | +.. include:: include.ipynb |
| 77 | + :parser: myst_nb.docutils_ |
| 78 | +``` |
| 79 | + |
| 80 | +```{important} |
| 81 | +The `parser` option requires `docutils>=0.17` |
| 82 | +``` |
0 commit comments