diff --git a/lammpsdoc/txt2html.py b/lammpsdoc/txt2html.py
index ab132a3..6e55972 100755
--- a/lammpsdoc/txt2html.py
+++ b/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/lammpsdoc/txt2rst.py b/lammpsdoc/txt2rst.py
index a4196e5..1bc279c 100755
--- a/lammpsdoc/txt2rst.py
+++ b/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/tests/test_txt2rst.py b/tests/test_txt2rst.py
index 1602fb6..2fa2bd6 100644
--- a/tests/test_txt2rst.py
+++ b/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"