From 5571afe97762480bc9343c528b28b2a31ded741e Mon Sep 17 00:00:00 2001 From: Aaron Gutierrez Date: Mon, 12 Mar 2018 21:02:18 -0700 Subject: [PATCH] Add list formatting --- models/models.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/models/models.py b/models/models.py index 0b40e17..abef38c 100644 --- a/models/models.py +++ b/models/models.py @@ -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)