Commit 3f312244 authored by Richard Berger's avatar Richard Berger Committed by Axel Kohlmeyer
Browse files

Escape RST special character '*' in final output

(cherry picked from commit 7cb39811d47b1f364286597acea21c3afd010733)
parent 55022d12
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -57,10 +57,15 @@ class RSTMarkup(Markup):
        return text

    def convert(self, text):
        text = self.escape_rst_chars(text)
        text = super().convert(text)
        text = self.inline_math(text)
        return text

    def escape_rst_chars(self, text):
        text = text.replace('*', '\\*')
        return text

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

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

    def test_paragraph_with_italic(self):
        self.assertEqual("A sentence with a *italic* word", self.markup.convert("A sentence with a {italic} word"))