diff --git a/htmlslacker/htmlslacker.py b/htmlslacker/htmlslacker.py index a81c5de..cbe63e6 100644 --- a/htmlslacker/htmlslacker.py +++ b/htmlslacker/htmlslacker.py @@ -23,6 +23,7 @@ def __init__(self, html, *args, **kwargs): except TypeError: HTMLParser.__init__(self, *args, **kwargs) self.skip = False + self.isProcessingList = False # slackified string self.output = '' @@ -55,6 +56,10 @@ def handle_starttag(self, tag, attrs): self.output += attr[1] + '|' if tag == 'style' or tag == 'script': self.skip = True + if tag == 'ul': + self.isProcessingList = True + if tag == 'li' and self.isProcessingList: + self.output += '• ' def handle_endtag(self, tag): """ @@ -72,6 +77,10 @@ def handle_endtag(self, tag): self.output += '`' if tag == 'style' or tag == 'script': self.skip = False + if tag == 'ul': + self.isProcessingList = False + if tag == 'li' and self.isProcessingList: + self.output += LINEBR def handle_data(self, data): """ diff --git a/test_general.py b/test_general.py index 3bd2a2f..6cccf01 100644 --- a/test_general.py +++ b/test_general.py @@ -35,3 +35,15 @@ def test_link_with_target(): expected = "Please click " output = HTMLSlacker(html).get_output() assert(output == expected) + +def test_unordered_list(): + html = 'Here is my cool list ' + expected = 'Here is my cool list • The Shining\n• Memento\n• Blade Runner\n' + output = HTMLSlacker(html).get_output() + assert(output == expected) + +def test_unordered_list_with_text_modifications(): + html = 'Here is my cool list ' + expected = 'Here is my cool list • The Shining\n• Memento\n• Blade *Runner*\n' + output = HTMLSlacker(html).get_output() + assert(output == expected)