chiark / gitweb /
m.code: support :hl-lines: in the .. include:: directive as well.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 9 Jun 2020 16:08:10 +0000 (18:08 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 9 Jun 2020 16:26:46 +0000 (18:26 +0200)
Not sure why original Docutils didn't have that.

doc/plugins/math-and-code.rst
plugins/m/code.py
plugins/m/test/code/code.cpp [new file with mode: 0644]
plugins/m/test/code/page.html
plugins/m/test/code/page.rst

index 6987dda415167ffb667f7d183ac261838e5cb789..f2fd8a2cb74b6ae1d9e02fd0c29700842698cc55 100644 (file)
@@ -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.
 
index 62cbad2f77083bbc8907e31c65a9ed4f7fcaaf0c..66d25e685eabcbf51d0de978dc1e84393ae5265c 100644 (file)
@@ -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 (file)
index 0000000..6346e2d
--- /dev/null
@@ -0,0 +1,3 @@
+int main() {
+    return 1;
+}
index 00608a47467e05e028c2f814b8a0d90f71f9113c..5858a9d59b09bb07d770319a6bde7c5577406327 100644 (file)
 <pre class="m-inverted m-code"><span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
 <span class="hll">    <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
 </span><span class="p">}</span></pre>
+<p>Same as above, but for a <code class="m-code"><span class="p">..</span> <span class="ow">include</span><span class="p">::</span></code>, which should also support line
+highlighting:</p>
+<pre class="m-inverted m-code"><span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
+<span class="hll">    <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
+</span><span class="p">}</span></pre>
 <p>Inline code is here: <code class="cpp m-code"><span class="k">constexpr</span></code>. Code without a language should be
 rendered as plain monospace text: <code>code</code>.</p>
 <pre class="m-console">!<span class="g g-AnsiBlue">[</span><span class="g g-AnsiBrightWhite">mosra@don-perverzo </span><span class="g g-AnsiWhite">m.css</span><span class="g g-AnsiBlue">]</span><span class="g g-AnsiBrightCyan">$ </span>ls
index 655041eb05d662cea97c2a5b783522e1ef1ddbc5..60b304a93bcd035f2a8d9e67707a16a3be151b61 100644 (file)
@@ -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`.