From 782837c3b600fcdf27c7b32eab81574ca2fb2688 Mon Sep 17 00:00:00 2001 From: Nour Saeed Date: Sun, 2 Feb 2020 02:47:39 -0800 Subject: [PATCH] ordered and unordered lists --- tomd.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tomd.py b/tomd.py index 999b13b..b43a65d 100644 --- a/tomd.py +++ b/tomd.py @@ -10,7 +10,6 @@ 'h5': "#####", 'h6': "######", "blockquote": ">", - "li": "-", "hr": "---", "p": "\n" } @@ -24,6 +23,11 @@ "code": ('`', '`') } +LISTS = { + 'ul': '-', + 'ol': '*' +} + split_str = "++++++++++++++++++" @@ -69,6 +73,16 @@ def convert(self, html=""): inline_mark = "```" + split_str + pq(e).html() + split_str + "```" + split_str html = html.replace(str(pq(e)), inline_mark) + d = pq(html) + selectors = ','.join(LISTS.keys()) + for e in d(selectors): + l = pq(e) + inline_mark = '

' + for i in l('li'): + inline_mark += split_str + MARKDOWN.get(e.tag) + " " + pq(i).text() + split_str + inline_mark += '

+ html = html.replace(str(pq(e)), inline_mark) + d = pq(html) selectors = ','.join(INLINE.keys()) for e in d(selectors):