chiark / gitweb /
m.code, m.math: test & fix nested backticks in interpreted roles.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 22 Aug 2019 20:19:41 +0000 (22:19 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sun, 25 Aug 2019 10:38:27 +0000 (12:38 +0200)
Broken when fixing backslash support.

plugins/m/code.py
plugins/m/math.py
plugins/m/test/code/page.html
plugins/m/test/code/page.rst

index 54ba1aa2366469431bee187f49b66f2364d378fd..465c0092e49573b48decdb57f951c3d740de185a 100644 (file)
@@ -178,9 +178,8 @@ class Include(docutils.parsers.rst.directives.misc.Include):
         return codeblock.run()
 
 def code(role, rawtext, text, lineno, inliner, options={}, content=[]):
-    # In order to properly preserve backslashes
-    i = rawtext.find('`')
-    text = rawtext.split('`')[1]
+    # In order to properly preserve backslashes (well, and backticks)
+    text = rawtext[rawtext.find('`') + 1:rawtext.rfind('`')]
 
     set_classes(options)
     classes = []
index 29498ade61f5dcf545b7c7a3fc467c9135bf1c19..f11ac57b665d03f128bde21eaa114cde5253bc7c 100644 (file)
@@ -104,9 +104,8 @@ def new_page(*args):
     latex2svgextra.counter = 0
 
 def math(role, rawtext, text, lineno, inliner, options={}, content=[]):
-    # Otherwise the backslashes do quite a mess there
-    i = rawtext.find('`')
-    text = rawtext.split('`')[1]
+    # In order to properly preserve backslashes (well, and backticks)
+    text = rawtext[rawtext.find('`') + 1:rawtext.rfind('`')]
 
     # Fallback rendering as code requested
     if settings['M_MATH_RENDER_AS_CODE']:
index 55d108804cce047f3d2bb4bf13998c7739e5c6a7..e806d052b0b4d35dffefb1db37238dc560dd3828 100644 (file)
@@ -41,7 +41,8 @@ Leading zeros: <span style="color: #0f7403; background-color: #0f7403">&zwnj;▒
 
 <span style="color: #3bd267">&zwnj;  </span> <span style="color: #3bd267">&zwnj;  </span> <span style="color: #3bd267">&zwnj;░░</span> <span style="color: #3bd267">&zwnj;▒▒</span> <span style="color: #3bd267">&zwnj;▓▓</span> <span style="color: #3bd267; background-color: #3bd267">&zwnj;██</span></pre>
 <pre class="m-code">// this language is not highlighted</pre>
-<p>Properly preserve backslashes: <code class="m-code"><span class="k">\frac</span><span class="nb">{</span>a<span class="nb">}{</span>b<span class="nb">}</span></code></p>
+<p>Properly preserve backslashes: <code class="m-code"><span class="k">\frac</span><span class="nb">{</span>a<span class="nb">}{</span>b<span class="nb">}</span></code> ... and backticks:
+<code class="m-code"><span class="na">:ref:</span><span class="nv">`a function &lt;os.path.join()&gt;`</span></code></p>
 <p>Don't trim leading spaces in blocks:</p>
 <pre class="m-code">        <span class="n">nope</span><span class="p">();</span>
     <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
index e3d92548eaaf9cb79f2a0cf7e2e15bca584fbc88..a4292a98720ecfbd0679d1b0d9ca88d80c53b795 100644 (file)
@@ -5,6 +5,8 @@ m.code
     :language: c++
 .. role:: tex(code)
     :language: tex
+.. role:: rst(code)
+    :language: rst
 
 .. code:: c++
 
@@ -35,7 +37,8 @@ Console colors:
 
     // this language is not highlighted
 
-Properly preserve backslashes: :tex:`\frac{a}{b}`
+Properly preserve backslashes: :tex:`\frac{a}{b}` ... and backticks:
+:rst:`:ref:`a function <os.path.join()>``
 
 Don't trim leading spaces in blocks: