From: Vladimír Vondruš Date: Thu, 22 Aug 2019 20:19:41 +0000 (+0200) Subject: m.code, m.math: test & fix nested backticks in interpreted roles. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=0b5960092b5f98121fd39f5efe43d8cdb0ea656b;p=blog.git m.code, m.math: test & fix nested backticks in interpreted roles. Broken when fixing backslash support. --- diff --git a/plugins/m/code.py b/plugins/m/code.py index 54ba1aa2..465c0092 100644 --- a/plugins/m/code.py +++ b/plugins/m/code.py @@ -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 = [] diff --git a/plugins/m/math.py b/plugins/m/math.py index 29498ade..f11ac57b 100644 --- a/plugins/m/math.py +++ b/plugins/m/math.py @@ -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']: diff --git a/plugins/m/test/code/page.html b/plugins/m/test/code/page.html index 55d10880..e806d052 100644 --- a/plugins/m/test/code/page.html +++ b/plugins/m/test/code/page.html @@ -41,7 +41,8 @@ Leading zeros: ‌▒ ‌░░ ‌▒▒ ‌▓▓ ‌██
// this language is not highlighted
-

Properly preserve backslashes: \frac{a}{b}

+

Properly preserve backslashes: \frac{a}{b} ... and backticks: +:ref:`a function <os.path.join()>`

Don't trim leading spaces in blocks:

        nope();
     return false;
diff --git a/plugins/m/test/code/page.rst b/plugins/m/test/code/page.rst
index e3d92548..a4292a98 100644
--- a/plugins/m/test/code/page.rst
+++ b/plugins/m/test/code/page.rst
@@ -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 ``
 
 Don't trim leading spaces in blocks: