chiark / gitweb /
m.code: don't blow up if inline literal doesn't have language.
authorVladimír Vondruš <mosra@centrum.cz>
Sat, 19 May 2018 11:31:02 +0000 (13:31 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 19 May 2018 11:35:27 +0000 (13:35 +0200)
pelican-plugins/m/code.py
pelican-plugins/m/test/code/page.html
pelican-plugins/m/test/code/page.rst

index 4bf996d3778475476b3e2138ee8432b4319d0508..cc999e9e0deccc39105acffa7cbc0310be32336a 100644 (file)
@@ -183,9 +183,16 @@ def code(role, rawtext, text, lineno, inliner, options={}, content=[]):
         classes += options['classes']
         del options['classes']
 
-    # Not sure why language is duplicated in classes?
-    language = options.get('language', '')
+    # If language is not specified, render a simple literal
+    if not 'language' in options:
+        content = nodes.raw('', utils.unescape(text), format='html')
+        node = nodes.literal(rawtext, '', **options)
+        node.append(content)
+        return [node], []
+
+    language = options['language']
     del options['language']
+    # Not sure why language is duplicated in classes?
     if language in classes: classes.remove(language)
 
     class_, highlighted = _highlight(utils.unescape(text), language, options)
index 16406a9d0f229c5a4e66c90eab086fdbaae60d69..6be7cc2eead9d37e4236b5879137641e407fa130 100644 (file)
@@ -29,7 +29,8 @@
 <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></p>
+<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
 CONTRIBUTING.rst  CREDITS.rst  <span class="g g-AnsiBrightBlue">doc</span>      <span class="g g-AnsiBrightBlue">pelican-plugins</span>  README.rst
 COPYING           <span class="g g-AnsiBrightBlue">css</span>          <span class="g g-AnsiBrightBlue">doxygen</span>  <span class="g g-AnsiBrightBlue">pelican-theme</span>    <span class="g g-AnsiBrightBlue">site</span></pre>
index 7cccd0a8ef9a4abcb1b26af81839a677da651772..48c5906a6bcc09f08f02b2a9eb0f4450208bcc30 100644 (file)
@@ -20,7 +20,8 @@ m.code
         return 1;
     }
 
-Inline code is here: :cpp:`constexpr`
+Inline code is here: :cpp:`constexpr`. Code without a language should be
+rendered as plain monospace text: :code:`code`.
 
 .. include:: console.ansi
     :code: ansi