From bfc0b365769ea2002c88c18fd1ef5996d933eb32 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 8 Jun 2020 20:42:34 +0200 Subject: [PATCH] m.code: add .. code-block:: and .. sourcecode:: aliases. --- doc/plugins/math-and-code.rst | 6 ++++++ plugins/m/code.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/doc/plugins/math-and-code.rst b/doc/plugins/math-and-code.rst index 5c300994..89bbded2 100644 --- a/doc/plugins/math-and-code.rst +++ b/doc/plugins/math-and-code.rst @@ -334,6 +334,12 @@ directive and specify the language via a parameter. Use :rst:`:hl_lines:` option to highlight lines; if you want to add additional CSS classes, use the :rst:`:class:` option. +.. note-dim:: + + Docutils (and Sphinx) have also :rst:`.. code-block::` and + :rst:`.. sourcecode::` aliases for the same thing. Those are included for + compatibility purposes and behave the same way as :rst:`.. code::`. + .. code-figure:: .. code:: rst diff --git a/plugins/m/code.py b/plugins/m/code.py index 6d2a5572..65e15302 100644 --- a/plugins/m/code.py +++ b/plugins/m/code.py @@ -285,6 +285,14 @@ def register_mcss(mcss_settings, **kwargs): rst.directives.register_directive('include', Include) rst.roles.register_canonical_role('code', code) + # These two are builtin aliases to .. code:: in docutils: + # https://github.com/docutils-mirror/docutils/blob/e88c5fb08d5cdfa8b4ac1020dd6f7177778d5990/docutils/parsers/rst/languages/en.py#L22-L24 + # Since a lot of existing markup (especially coming from Sphinx) uses + # .. code-block:: and since there's no reason for .. code-block:: / + # .. sourcecode:: to behave like unpatched docutils, let's add those too: + rst.directives.register_directive('code-block', Code) + rst.directives.register_directive('sourcecode', Code) + global filters_pre, filters_post filters_pre = mcss_settings.get('M_CODE_FILTERS_PRE', {}) filters_post = mcss_settings.get('M_CODE_FILTERS_POST', {}) -- 2.30.2