chiark / gitweb /
m.code: change to :hl-lines: instead of :hl_lines:.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 9 Jun 2020 16:02:55 +0000 (18:02 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 9 Jun 2020 16:07:39 +0000 (18:07 +0200)
I can't stress how much I hated the underscore. Turns out it's there
ONLY because Pygments have an underscore, otherwise there would be a
dash like with all other directives/options/roles. Eh.

The legacy option is still recognized of course.

doc/plugins/math-and-code.rst
plugins/m/code.py
plugins/m/test/code/page.html
plugins/m/test/code/page.rst

index 6de8a130ba5a6ce2cb3f4e354d84a7519b19d17d..6987dda415167ffb667f7d183ac261838e5cb789 100644 (file)
@@ -330,7 +330,7 @@ replaces `Pelican code-block directive <https://docs.getpelican.com/en/stable/co
 -   Adds a :rst:`:filters:` option. See `Filters`_ below.
 
 Put `code blocks <{filename}/css/components.rst#code>`_ into the :rst:`.. code::`
-directive and specify the language via a parameter. Use :rst:`:hl_lines:`
+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.
 
@@ -345,7 +345,7 @@ option to highlight lines; if you want to add additional CSS classes, use the
     .. code:: rst
 
         .. code:: c++
-            :hl_lines: 4 5
+            :hl-lines: 4 5
             :class: m-inverted
 
             #include <iostream>
@@ -356,7 +356,7 @@ option to highlight lines; if you want to add additional CSS classes, use the
             }
 
     .. code:: c++
-        :hl_lines: 4 5
+        :hl-lines: 4 5
         :class: m-inverted
 
         #include <iostream>
index c854176f7c408419aefde324f21ec6b36c02ed69..62cbad2f77083bbc8907e31c65a9ed4f7fcaaf0c 100644 (file)
@@ -62,6 +62,11 @@ def _highlight(code, language, options, *, is_block, filters=[]):
     else:
         class_ = 'm-code'
 
+    # Pygments wants the underscored option
+    if 'hl-lines' in options:
+        options['hl_lines'] = options['hl-lines']
+        del options['hl-lines']
+
     if isinstance(lexer, ansilexer.AnsiLexer):
         formatter = ansilexer.HtmlAnsiFormatter(**options)
     else:
@@ -97,6 +102,8 @@ class Code(Directive):
     optional_arguments = 0
     final_argument_whitespace = True
     option_spec = {
+        'hl-lines': directives.unchanged,
+        # Legacy alias to hl-lines (I hate underscores)
         'hl_lines': directives.unchanged,
         'class': directives.class_option,
         'filters': directives.unchanged
@@ -112,6 +119,11 @@ class Code(Directive):
             classes += self.options['classes']
             del self.options['classes']
 
+        # Legacy alias to hl-lines
+        if 'hl_lines' in self.options:
+            self.options['hl-lines'] = self.options['hl_lines']
+            del self.options['hl_lines']
+
         filters = self.options.pop('filters', '').split()
 
         class_, highlighted = _highlight('\n'.join(self.content), self.arguments[0], self.options, is_block=True, filters=filters)
index 9ae6384b895f2aeea2e547ef5c2b88f9cbfe156a..00608a47467e05e028c2f814b8a0d90f71f9113c 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>Legacy <code class="m-code"><span class="nc">:hl_lines:</span></code> option should work the same:</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 91e819a294bd7685f2fa6d2327d5f0506052ac5a..655041eb05d662cea97c2a5b783522e1ef1ddbc5 100644 (file)
@@ -16,6 +16,16 @@ m.code
         return 0;
     }
 
+.. code:: c++
+    :class: m-inverted
+    :hl-lines: 2
+
+    int main() {
+        return 1;
+    }
+
+Legacy :rst:`:hl_lines:` option should work the same:
+
 .. code:: c++
     :class: m-inverted
     :hl_lines: 2