diff --git a/doc/utils/converters/lammpsdoc/txt2html.py b/doc/utils/converters/lammpsdoc/txt2html.py index ddb1b1978e..ab132a380d 100755 --- a/doc/utils/converters/lammpsdoc/txt2html.py +++ b/doc/utils/converters/lammpsdoc/txt2html.py @@ -138,12 +138,18 @@ class Formatting(object): elif command == "dl": return self.definition_list(paragraph) elif command == "l": + if "olb" in commands: + self.current_list_mode = Formatting.ORDERED_LIST_MODE + elif "ulb" in commands: + self.current_list_mode = Formatting.UNORDERED_LIST_MODE + return self.list_item(paragraph) elif command == "dt": return self.definition_term(paragraph) elif command == "dd": return self.definition_description(paragraph) elif command == "ulb": + self.current_list_mode = Formatting.UNORDERED_LIST_MODE return self.unordered_list_begin(paragraph) elif command == "ule": return self.unordered_list_end(paragraph) diff --git a/doc/utils/converters/lammpsdoc/txt2rst.py b/doc/utils/converters/lammpsdoc/txt2rst.py index ba3864008a..f9ceb9b7ae 100755 --- a/doc/utils/converters/lammpsdoc/txt2rst.py +++ b/doc/utils/converters/lammpsdoc/txt2rst.py @@ -165,7 +165,7 @@ class RSTFormatting(Formatting): return paragraph def unordered_list_end(self, paragraph): - return paragraph + return paragraph.rstrip() + '\n' def ordered_list_begin(self, paragraph): if paragraph.startswith('* '): @@ -179,7 +179,15 @@ class RSTFormatting(Formatting): return paragraph def ordered_list_end(self, paragraph): - return paragraph + return paragraph.rstrip() + '\n' + + def ordered_list(self, paragraph): + paragraph = super().ordered_list(paragraph) + return paragraph.rstrip() + '\n' + + def unordered_list(self, paragraph): + paragraph = super().unordered_list(paragraph) + return paragraph.rstrip() + '\n' def all_breaks(self, paragraph): indented = "" diff --git a/doc/utils/converters/tests/test_txt2rst.py b/doc/utils/converters/tests/test_txt2rst.py index 1be59ac714..e2c20434be 100644 --- a/doc/utils/converters/tests/test_txt2rst.py +++ b/doc/utils/converters/tests/test_txt2rst.py @@ -222,7 +222,7 @@ class TestListFormatting(unittest.TestCase): "three :ule,l\n") self.assertEqual("* one\n" "* two\n" - "* three\n", s) + "* three\n\n", s) def test_multi_line_unordered_list_elements(self): s = self.txt2rst.convert("one :ulb,l\n" @@ -232,7 +232,7 @@ class TestListFormatting(unittest.TestCase): self.assertEqual("* one\n" "* two\n" " words\n" - "* three\n", s) + "* three\n\n", s) def test_ordered_list(self): s = self.txt2rst.convert("one\n" @@ -248,7 +248,7 @@ class TestListFormatting(unittest.TestCase): "three :ole,l\n") self.assertEqual("#. one\n" "#. two\n" - "#. three\n", s) + "#. three\n\n", s) def test_multi_line_ordered_list_elements(self): s = self.txt2rst.convert("one :olb,l\n" @@ -258,7 +258,37 @@ class TestListFormatting(unittest.TestCase): self.assertEqual("#. one\n" "#. two\n" " words\n" - "#. three\n", s) + "#. three\n\n", s) + + def test_paragraphs_ordered_list(self): + s = self.txt2rst.convert("first\n" + "paragraph :olb,l\n" + "second\n" + "paragraph :l\n" + "third\n" + "paragraph :ole,l\n") + self.assertEqual("#. first\n" + " paragraph\n" + "#. second\n" + " paragraph\n" + "#. third\n" + " paragraph\n\n", s) + + def test_paragraphs_unordered_list(self): + s = self.txt2rst.convert("first\n" + "paragraph :ulb,l\n" + "second\n" + "paragraph :l\n" + "third\n" + "paragraph :ule,l\n") + self.assertEqual("* first\n" + " paragraph\n" + "* second\n" + " paragraph\n" + "* third\n" + " paragraph\n\n", s) + + def test_definition_list(self): s = self.txt2rst.convert("A\n"