- 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.
.. code:: rst
.. code:: c++
- :hl_lines: 4 5
+ :hl-lines: 4 5
:class: m-inverted
#include <iostream>
}
.. code:: c++
- :hl_lines: 4 5
+ :hl-lines: 4 5
:class: m-inverted
#include <iostream>
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:
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
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)
<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