From: Vladimír Vondruš Date: Tue, 9 Jun 2020 16:08:10 +0000 (+0200) Subject: m.code: support :hl-lines: in the .. include:: directive as well. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=f24cc59946122a75d51f8910d1d4d8fe9ec1170a;p=blog.git m.code: support :hl-lines: in the .. include:: directive as well. Not sure why original Docutils didn't have that. --- diff --git a/doc/plugins/math-and-code.rst b/doc/plugins/math-and-code.rst index 6987dda4..f2fd8a2c 100644 --- a/doc/plugins/math-and-code.rst +++ b/doc/plugins/math-and-code.rst @@ -371,6 +371,8 @@ is also patched to use the improved code directive, and: - Drops the rarely useful :rst:`:encoding:`, :rst:`:literal:` and :rst:`:name:` options +- Adds a :rst:`:hl-lines:` option to have the same behavior as + the :rst:`.. code::` directive - Adds a :rst:`:start-on:` and :rst:`:strip-prefix:` options, and improves :rst:`:end-before:`. See `Advanced file inclusion`_ below. diff --git a/plugins/m/code.py b/plugins/m/code.py index 62cbad2f..66d25e68 100644 --- a/plugins/m/code.py +++ b/plugins/m/code.py @@ -145,7 +145,8 @@ class Include(docutils.parsers.rst.directives.misc.Include): 'end-before': directives.unchanged, 'strip-prefix': directives.unchanged, 'class': directives.class_option, - 'filters': directives.unchanged + 'filters': directives.unchanged, + 'hl-lines': directives.unchanged } def run(self): diff --git a/plugins/m/test/code/code.cpp b/plugins/m/test/code/code.cpp new file mode 100644 index 00000000..6346e2d2 --- /dev/null +++ b/plugins/m/test/code/code.cpp @@ -0,0 +1,3 @@ +int main() { + return 1; +} diff --git a/plugins/m/test/code/page.html b/plugins/m/test/code/page.html index 00608a47..5858a9d5 100644 --- a/plugins/m/test/code/page.html +++ b/plugins/m/test/code/page.html @@ -33,6 +33,11 @@
int main() {
     return 1;
 }
+

Same as above, but for a .. include::, which should also support line +highlighting:

+
int main() {
+    return 1;
+}

Inline code is here: constexpr. Code without a language should be rendered as plain monospace text: code.

![mosra@don-perverzo m.css]$ ls
diff --git a/plugins/m/test/code/page.rst b/plugins/m/test/code/page.rst
index 655041eb..60b304a9 100644
--- a/plugins/m/test/code/page.rst
+++ b/plugins/m/test/code/page.rst
@@ -34,6 +34,14 @@ Legacy :rst:`:hl_lines:` option should work the same:
         return 1;
     }
 
+Same as above, but for a :rst:`.. include::`, which should also support line
+highlighting:
+
+.. include:: code.cpp
+    :code: c++
+    :class: m-inverted
+    :hl-lines: 2
+
 Inline code is here: :cpp:`constexpr`. Code without a language should be
 rendered as plain monospace text: :code:`code`.