|
| 1 | +[![Licence][licence-badge]][licence-link] |
| 2 | +[![Python][python-badge]][python-link] |
| 3 | +[![PyPI][pypi-badge]][pypi-link] |
| 4 | +[![Documentation][doc-badge]][doc-link] |
| 5 | + |
| 6 | +[licence-badge]: https://img.shields.io/github/license/so-cool/sphinx-term.svg |
| 7 | +[licence-link]: https://github.com/so-cool/sphinx-term/blob/master/LICENCE |
| 8 | +[python-badge]: https://img.shields.io/badge/python-3.5-blue.svg |
| 9 | +[python-link]: https://github.com/so-cool/sphinx-term |
| 10 | +[pypi-badge]: https://img.shields.io/pypi/v/sphinx-term.svg |
| 11 | +[pypi-link]: https://pypi.org/project/sphinx-term |
| 12 | +[doc-badge]: https://img.shields.io/badge/read-documentation-blue.svg |
| 13 | +[doc-link]: https://so-cool.github.io/sphinx-term |
| 14 | + |
| 15 | +# :computer: Terminal extension for Jupyter Book (and Sphinx) # |
| 16 | + |
| 17 | +This repository holds *terminal* extensions for [Sphinx], designed to be used |
| 18 | +with the [Jupyter Book] platform. |
| 19 | +It implements **vivacious terminal transcripts** that can be easily embedded |
| 20 | +in your [Sphinx] documentation and [Jupyter Book] pages. |
| 21 | +The `sphinx-term` extension relies on two web terminal window packages: |
| 22 | +* [termynal]; and |
| 23 | +* [cssterm]. |
| 24 | + |
| 25 | +**This readme file holds a technical documentation of the `sphinx-term` |
| 26 | +extension. |
| 27 | +For a [Jupyter Book] user guide and usage example of the terminal boxes |
| 28 | +visit the [example page] hosted on GitHub Pages, the source of which is |
| 29 | +available in the [docs] folder of this repository.** |
| 30 | + |
| 31 | +> This *readme* file uses [Jupyter Book]'s [MyST Markdown] syntax for **roles** |
| 32 | + and **directives** -- see [MyST overview] for more details. |
| 33 | + For use with [Sphinx], please refer to the [reStructuredText] syntax. |
| 34 | + |
| 35 | +## :snake: Installing `sphinx-term` ## |
| 36 | + |
| 37 | +To get started with `sphinx-term`, first install it via `pip`: |
| 38 | +```bash |
| 39 | +pip install sphinx-term |
| 40 | +``` |
| 41 | +then, add the `cssterm` and/or `termynal` module of the `sphinx_term` |
| 42 | +extension to the Sphinx `extensions` list in your `conf.py` |
| 43 | +```Python |
| 44 | +... |
| 45 | +extensions = [ |
| 46 | + 'sphinx_term.cssterm', |
| 47 | + 'sphinx_term.termynal' |
| 48 | +] |
| 49 | +... |
| 50 | +``` |
| 51 | + |
| 52 | +## :keyboard: cssterm directive ## |
| 53 | + |
| 54 | +The [`sphinx_term.cssterm`](sphinx_term/cssterm.py) module defines the |
| 55 | +`cssterm` directive, which is used for building [cssterm] terminal windows. |
| 56 | + |
| 57 | +### Usage ### |
| 58 | + |
| 59 | +A *[cssterm] terminal box* is included with the `cssterm` directive: |
| 60 | + |
| 61 | +````text |
| 62 | +```{cssterm} cssterm:my-id |
| 63 | +$ echo "My terminal transcript" |
| 64 | +My terminal transcript |
| 65 | +``` |
| 66 | +```` |
| 67 | + |
| 68 | +Each [cssterm] box can be referenced with its name using the `ref` role, |
| 69 | +e.g., `` {ref}`cssterm:my-id` ``, which produces *terminal box* hyper-link. |
| 70 | +The default hyper-link text can be changed with with the folowing `ref` role |
| 71 | +syntax: `` {ref}`custom hyper-link text <cssterm:my-id>` ``. |
| 72 | +See the [MyST Markdown documentation] for more details. |
| 73 | + |
| 74 | +### Configuration parameters ### |
| 75 | + |
| 76 | +The `cssterm` extension uses one [Sphinx] configuration parameter: |
| 77 | + |
| 78 | +* `sphinx_term_cssterm_dir` (**required** when loading the box content |
| 79 | + from a file) -- defines the path to a directory holding files with content |
| 80 | + (terminal transcript) of each terminal box. |
| 81 | + |
| 82 | +### Arguments, parameters and content ### |
| 83 | + |
| 84 | +Each [cssterm] box has one **required** argument that specifies |
| 85 | +the *unique* id of this particular terminal block. |
| 86 | +This id **must** start with the `cssterm:` prefix. |
| 87 | +The content of a [cssterm] box can **either** be provided explicitly within the |
| 88 | +directive, **or** -- when the content is left empty -- it is pulled from a |
| 89 | +terminal transcript file whose name is derived from the terminal box id, |
| 90 | +and which should be located in the directory specified via the |
| 91 | +`sphinx_term_cssterm_dir` configuration parameter. |
| 92 | +The terminal transcript file name is expected to be the [cssterm] block id |
| 93 | +**without** the `cssterm:` prefix and **with** the `.log` extension. |
| 94 | +For example, for a [cssterm] block with `cssterm:my_log` id, the terminal |
| 95 | +transcript file should be named `my_code.log`. |
| 96 | +The `sphinx_term.cssterm` [Sphinx] extension *monitors* the code files for |
| 97 | +changes and automatically regenerates the affected pages. |
| 98 | + |
| 99 | +## :keyboard: termynal directive ## |
| 100 | + |
| 101 | +*Work in progress.* |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +> The CSS and JS files used by this [Sphinx] extension are loaded as |
| 106 | + git submodules into the [`sphinx_term/_static`](sphinx_term/_static) |
| 107 | + directory of this repository. |
| 108 | + |
| 109 | +[sphinx]: https://www.sphinx-doc.org/ |
| 110 | +[jupyter book]: https://jupyterbook.org/ |
| 111 | +[termynal]: https://github.com/ines/termynal |
| 112 | +[cssterm]: https://github.com/nstephens/cssterm |
| 113 | +[example page]: https://so-cool.github.io/sphinx-term |
| 114 | +[doc]: docs |
| 115 | +[myst markdown]: https://myst-parser.readthedocs.io/ |
| 116 | +[myst overview]: https://jupyterbook.org/content/myst.html |
| 117 | +[reStructuredText]: https://docutils.sourceforge.io/rst.html |
| 118 | +[MyST Markdown documentation]: https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html#targets-and-cross-referencing |
0 commit comments