Add list formatting

This commit is contained in:
2018-03-12 21:02:18 -07:00
parent c97f79a081
commit 5571afe977

View File

@@ -134,6 +134,20 @@ class Tag(object):
def text_format(self):
return self.body.text_format()
class List(object):
def __init__(self, body):
self.body = body
def text_format(self):
return self.body.text_format() + '\n'
class ListItem(object):
def __init__(self, body):
self.body = body
def text_format(self):
return '' + self.body.text_format() + '\n'
class Text(object):
def __init__(self, body):
self.body = body
@@ -156,6 +170,10 @@ class HTMLTextParser(HTMLParser):
self.tag_stack.append(Underline)
elif tag == 'a':
self.tag_stack.append(Link)
elif tag == 'ul' or tag == 'ol':
self.tag_stack.append(List)
elif tag == 'li':
self.tag_stack.append(ListItem)
else:
self.tag_stack.append(Tag)