diff --git a/doc/utils/converters/lammpsdoc/txt2html.py b/doc/utils/converters/lammpsdoc/txt2html.py index ab132a380dbb82d3dd2ebe58dc29a8a3139b1078..6e559723b4fd0a850219f866704d2f05b02c35dc 100755 --- a/doc/utils/converters/lammpsdoc/txt2html.py +++ b/doc/utils/converters/lammpsdoc/txt2html.py @@ -518,6 +518,9 @@ class TxtParser(object): def last_word(self, text): return text.split()[-1] + def order_commands(self, commands): + return list(reversed(commands)) + def do_formatting(self, paragraph): last_word = self.last_word(paragraph) format_str = paragraph[paragraph.rfind(last_word):] @@ -529,7 +532,7 @@ class TxtParser(object): commands = [x[0] for x in command_pattern.findall(commands)] - for command in reversed(commands): + for command in self.order_commands(commands): paragraph = self.format.convert(command, paragraph, commands) return paragraph + '\n' diff --git a/doc/utils/converters/lammpsdoc/txt2rst.py b/doc/utils/converters/lammpsdoc/txt2rst.py index a4196e501b665330514be404eb69a286ee125e9d..1bc279c0f30e48177948d508266b0cff071b196f 100755 --- a/doc/utils/converters/lammpsdoc/txt2rst.py +++ b/doc/utils/converters/lammpsdoc/txt2rst.py @@ -347,6 +347,14 @@ class Txt2Rst(TxtParser): def is_raw_textblock_end(self, line): return line.startswith('END_RST -->') + def order_commands(self, commands): + if 'ule' in commands and 'l' in commands and commands.index('ule') > commands.index('l'): + return commands + elif 'ole' in commands and 'l' in commands and commands.index('ole') > commands.index('l'): + return commands + return super().order_commands(commands) + + class Txt2RstConverter(TxtConverter): def get_argument_parser(self): parser = argparse.ArgumentParser(description='converts a text file with simple formatting & markup into ' diff --git a/doc/utils/converters/tests/test_txt2rst.py b/doc/utils/converters/tests/test_txt2rst.py index 1602fb61f9e5593c76c268bf58dee3e42a487879..2fa2bd699ee7048c86e4563fe805826861574f3b 100644 --- a/doc/utils/converters/tests/test_txt2rst.py +++ b/doc/utils/converters/tests/test_txt2rst.py @@ -236,6 +236,14 @@ class TestListFormatting(unittest.TestCase): "* two\n" "* three\n\n", s) + def test_elementwise_unordered_list_reverse(self): + s = self.txt2rst.convert("one :ulb,l\n" + "two :l\n" + "three :l,ule\n") + self.assertEqual("* one\n" + "* two\n" + "* three\n\n", s) + def test_multi_line_unordered_list_elements(self): s = self.txt2rst.convert("one :ulb,l\n" "two\n"