chiark / gitweb /
m.code: add .. code-block:: and .. sourcecode:: aliases.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 8 Jun 2020 18:42:34 +0000 (20:42 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 8 Jun 2020 18:42:34 +0000 (20:42 +0200)
doc/plugins/math-and-code.rst
plugins/m/code.py

index 5c300994e9028b59ace834a3070bfd2d7502f4db..89bbded296afbfa1ea212f1be7a0c6310e30be9e 100644 (file)
@@ -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
index 6d2a55724014de2bf9d123647fc53b341ebbbb9f..65e153027b29923e3abdca9d6ca63b591dab6c3f 100644 (file)
@@ -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', {})