Enforce l,ule or l,ole command order for RST

(cherry picked from commit 79e867c213)
This commit is contained in:
Richard Berger
2016-09-07 01:31:56 -04:00
committed by Axel Kohlmeyer
parent 9e8256aeb0
commit 4c783ea3b7
3 changed files with 20 additions and 1 deletions

View File

@ -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'

View File

@ -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 '

View File

@ -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"