diff --git a/doc/utils/converters/lammpsdoc/txt2rst.py b/doc/utils/converters/lammpsdoc/txt2rst.py index f9ceb9b7ae..aec1b0d02d 100755 --- a/doc/utils/converters/lammpsdoc/txt2rst.py +++ b/doc/utils/converters/lammpsdoc/txt2rst.py @@ -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("\\)") diff --git a/doc/utils/converters/tests/test_txt2rst.py b/doc/utils/converters/tests/test_txt2rst.py index e2c20434be..9403d419a8 100644 --- a/doc/utils/converters/tests/test_txt2rst.py +++ b/doc/utils/converters/tests/test_txt2rst.py @@ -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"))