mosra / m.css

A no-nonsense, no-JavaScript CSS framework, site and documentation theme for content-oriented websites
https://mcss.mosra.cz
Other
409 stars 92 forks source link

Support reStructuredText code directive aliases #153

Closed gsauthof closed 4 years ago

gsauthof commented 4 years ago

The m.code plugin overwrites the docutils code directive such that the CSS class m-code is emitted instead of the default highlight class, in the generated html.

It turns out that docutils currently define 3 code block directives that alias each other, namely code, code-block and sourcecode:

https://github.com/docutils-mirror/docutils/blob/e88c5fb08d5cdfa8b4ac1020dd6f7177778d5990/docutils/parsers/rst/languages/en.py#L22-L24

Current documentation even only mentions code-block and sourcecode.

Since I've some existing .rst files that use code-block I quickly patched code.py which seems to work so far:

--- a/plugins/m/code.py
+++ b/plugins/m/code.py
@@ -282,6 +282,7 @@ code.options = {'class': directives.class_option,

 def register_mcss(mcss_settings, **kwargs):
     rst.directives.register_directive('code', Code)
+    rst.directives.register_directive('code-block', Code)
     rst.directives.register_directive('include', Include)
     rst.roles.register_canonical_role('code', code)

Perhaps there is a better way to fix this instead of registering code-block and sourcecode in this way.

mosra commented 4 years ago

Hi,

I was aware there's a bunch of aliases (and Sphinx for some reason prefers the most verbose one) but to me those seemed unnecessarily redundant, so I overrode just the .. code:: one. But now, after thinking about this a bit more, it doesn't make sense to have .. code:: work while .. code-block:: still uses the unpatched/broken vanilla directive. So I added both aliases in bfc0b365769ea2002c88c18fd1ef5996d933eb32.