Jupyter-book#

Install#

sudo apt install plantuml                 # for sphinxcontrib-plantuml
pip install -U jupyter-book
pip install --upgrade docutils
pip install Pillow
pip install -U sphinxcontrib-plantuml
pip install -U sphinxcontrib-tikz

MyST#

Directives - a block-level extension point

https://myst-parser.readthedocs.io/en/latest/syntax/roles-and-directives.html#syntax-directives

Pygments#

Lexers#

https://pygments.org/docs/lexers/

Extension for pygments#

文件列表

$ tree -L 2 --filesfirst --charset=ascii ../extension 
../extension
|-- README.md
|-- pyproject.toml
`-- xyzutils
    |-- __init__.py
    |-- colab_python.py
    `-- __pycache__

2 directories, 4 files
Listing 1 …/extension/pyproject.toml#
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "xyzutils"
version = "0.0.1"
dependencies = [
    "pygments",
    'importlib-metadata',
]

[project.entry-points."pygments.lexers"]
yourlexer = "xyzutils:ColabPythonLexer"
Listing 2 …/extension/xyzutils/init.py#
from .colab_python import *
Listing 3 …/extension/xyzutils/colab_python.py#
from pygments.lexer import RegexLexer, inherit
from pygments.lexers import PythonLexer
from pygments.token import *

__all__ = ( "ColabPythonLexer", )

class ColabPythonLexer(PythonLexer):
    """All your lexer code goes here!"""
    name = 'colab-python'
    aliases = ['colabpy']
    filenames = ['*.colabpy']

    tokens = {
        'root': [
            (r'\s+\!([^\n]+\\\n)*[^\n]*[^\\]\n', String),
            inherit
        ]
    }

if __name__ == '__main__':
    pass