Commit 546582ea authored by Richard Berger's avatar Richard Berger
Browse files

Escape pipe characters

parent b76a42d3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ class RSTMarkup(Markup):
    def escape_rst_chars(self, text):
        text = text.replace('*', '\\*')
        text = text.replace('^', '\\^')
        text = text.replace('|', '\\|')
        text = re.sub(r'([^"])_', r'\1\\_', text)
        return text

@@ -72,6 +73,7 @@ class RSTMarkup(Markup):
        text = text.replace('\\*', '*')
        text = text.replace('\\^', '^')
        text = text.replace('\\_', '_')
        text = text.replace('\\|', '|')
        return text

    def inline_math(self, text):
+4 −0
Original line number Diff line number Diff line
@@ -81,6 +81,10 @@ class TestMarkup(unittest.TestCase):
        s = self.markup.convert("[*bold] and {italic*}")
        self.assertEqual("**\*bold** and *italic\**", s)

    def test_escape_rst_characters(self):
      s = self.markup.convert("[|bold|] and {|italic|}")
      self.assertEqual("**\|bold\|** and *\|italic\|*", s)

    def test_escape_hat_character(self):
        s = self.markup.convert("x^2")
        self.assertEqual("x\^2", s)