diff --git a/doc/utils/converters/lammpsdoc/txt2rst.py b/doc/utils/converters/lammpsdoc/txt2rst.py index 2e4e7a04f8ff571d9694e50bd54cc9d387991ff0..b4e8d6328645f14504695a3ca9412e85d8019abf 100755 --- a/doc/utils/converters/lammpsdoc/txt2rst.py +++ b/doc/utils/converters/lammpsdoc/txt2rst.py @@ -119,8 +119,12 @@ class RSTFormatting(Formatting): def __init__(self, markup): super().__init__(markup) + self.indent_level = 0 def paragraph(self, content): + if self.indent_level > 0: + return '\n' + self.list_indent(content.strip(), self.indent_level) + return content.strip() + "\n" def center(self, content): @@ -130,7 +134,9 @@ class RSTFormatting(Formatting): return content.strip() def preformat(self, content): - return ".. parsed-literal::\n\n" + self.indent(content.rstrip()) + 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()) def horizontal_rule(self, content): return "\n----------\n\n" + content.strip() @@ -180,14 +186,17 @@ class RSTFormatting(Formatting): return self.indent(paragraph.strip()) def unordered_list_begin(self, paragraph): + self.indent_level += 1 return paragraph def unordered_list_end(self, paragraph): + self.indent_level -= 1 return paragraph.rstrip() + '\n' def ordered_list_begin(self, paragraph): if paragraph.startswith('* '): paragraph = '#. ' + paragraph[2:] + self.indent_level += 1 return paragraph def definition_list_begin(self, paragraph): @@ -197,6 +206,7 @@ class RSTFormatting(Formatting): return paragraph def ordered_list_end(self, paragraph): + self.indent_level -= 1 return paragraph.rstrip() + '\n' def ordered_list(self, paragraph): @@ -230,6 +240,12 @@ class RSTFormatting(Formatting): indented += " %s\n" % line return indented + def list_indent(self, content, level=1): + indented = "" + for line in content.splitlines(): + indented += " " * level + ("%s\n" % line) + return indented + def get_max_column_widths(self, rows): num_columns = max([len(row) for row in rows]) max_widths = [0] * num_columns diff --git a/doc/utils/converters/tests/test_txt2rst.py b/doc/utils/converters/tests/test_txt2rst.py index 743e154b0c18504ed3beb7d04d282c020bb02287..e9b66d492879e08f41d9067706c36612e844c27d 100644 --- a/doc/utils/converters/tests/test_txt2rst.py +++ b/doc/utils/converters/tests/test_txt2rst.py @@ -317,8 +317,6 @@ class TestListFormatting(unittest.TestCase): "* third\n" " paragraph\n\n", s) - - def test_definition_list(self): s = self.txt2rst.convert("A\n" "first\n" @@ -331,6 +329,39 @@ class TestListFormatting(unittest.TestCase): " second\n" "\n\n", s) + def test_multi_paragraph_lists(self): + s = self.txt2rst.convert("first\n" + "paragraph of first bullet :ulb,l\n\n" + "second paragraph of first bullet\n\n" + "first paragraph of second bullet :l\n\n" + ":ule\n") + self.assertEqual("* first\n" + " paragraph of first bullet\n" + "\n" + " second paragraph of first bullet\n" + "\n" + "* first paragraph of second bullet\n\n\n", s) + + def test_multi_paragraph_lists_with_listing(self): + s = self.txt2rst.convert("first\n" + "paragraph of first bullet :ulb,l\n\n" + "code1 :pre\n" + "or\n" + "\n" + "first paragraph of second bullet :l\n\n" + ":ule\n") + self.assertEqual("* first\n" + " paragraph of first bullet\n" + " \n" + " .. parsed-literal::\n" + " \n" + " code1\n" + "\n\n" + " or\n" + "\n" + "* first paragraph of second bullet\n\n\n", s) + + class TestSpecialCommands(unittest.TestCase): def setUp(self): self.txt2rst = txt2rst.Txt2Rst()