From 67d4c07689a357476ef0b3ebd621c2d14237636b Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 26 Sep 2016 16:56:24 -0400 Subject: [PATCH] Do not escape underscore inside preformat blocks --- doc/utils/converters/lammpsdoc/txt2rst.py | 6 +++++- doc/utils/converters/tests/test_txt2rst.py | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/utils/converters/lammpsdoc/txt2rst.py b/doc/utils/converters/lammpsdoc/txt2rst.py index 0997af80cd..5c371bcfdc 100755 --- a/doc/utils/converters/lammpsdoc/txt2rst.py +++ b/doc/utils/converters/lammpsdoc/txt2rst.py @@ -73,10 +73,13 @@ class RSTMarkup(Markup): def unescape_rst_chars(self, text): text = text.replace('\\*', '*') text = text.replace('\\^', '^') - text = text.replace('\\_', '_') + text = self.unescape_underscore(text) text = text.replace('\\|', '|') return text + def unescape_underscore(self, text): + return text.replace('\\_', '_') + def inline_math(self, text): start_pos = text.find("\\(") end_pos = text.find("\\)") @@ -136,6 +139,7 @@ class RSTFormatting(Formatting): return content.strip() def preformat(self, content): + content = self.markup.unescape_underscore(content) if self.indent_level > 0: return self.list_indent("\n.. parsed-literal::\n\n" + self.indent(content.rstrip()), self.indent_level) return "\n.. parsed-literal::\n\n" + self.indent(content.rstrip()) diff --git a/doc/utils/converters/tests/test_txt2rst.py b/doc/utils/converters/tests/test_txt2rst.py index 904eeb4749..f74f8b70dd 100644 --- a/doc/utils/converters/tests/test_txt2rst.py +++ b/doc/utils/converters/tests/test_txt2rst.py @@ -169,6 +169,13 @@ class TestFormatting(unittest.TestCase): " Hello\n" " World\n\n", s) + def test_preformat_formatting_with_underscore(self): + s = self.txt2rst.convert("if MPI.COMM_WORLD.rank == 0:\n" + " print(\"Potential energy: \", L.eval(\"pe\")) :pre\n") + self.assertEqual("\n.. parsed-literal::\n\n" + " if MPI.COMM_WORLD.rank == 0:\n" + " print(\"Potential energy: \", L.eval(\"pe\"))\n\n", s) + def test_header_formatting(self): s = self.txt2rst.convert("Level 1 :h1\n" "Level 2 :h2\n"