Skip to content
Snippets Groups Projects
Commit 67d4c076 authored by Richard Berger's avatar Richard Berger
Browse files

Do not escape underscore inside preformat blocks

parent 877a5049
No related branches found
No related tags found
No related merge requests found
......@@ -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())
......
......@@ -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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment