summaryrefslogtreecommitdiffstats
path: root/md_tw.py
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2018-02-19 05:10:02 +0000
committerrsiddharth <s@ricketyspace.net>2018-02-19 05:10:02 +0000
commitc65420d1518032fdf20fdeb5030f6b27598c2486 (patch)
tree6059675625a8a6e43ba5415f6243027464e8abe2 /md_tw.py
parentf5651b545bfe56d53f6d5598fa9c057cdd458f78 (diff)
md_tw.py: Add TWMarkdown.output_list_item.
* md_tw.py (TWMarkdown)[output_list_item]: New method.
Diffstat (limited to 'md_tw.py')
-rw-r--r--md_tw.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/md_tw.py b/md_tw.py
index 2d8b7bc..2b3f357 100644
--- a/md_tw.py
+++ b/md_tw.py
@@ -355,6 +355,47 @@ class TWMarkdown(mistune.Markdown):
text = self.token['text']
return self.renderer.block_html(text)
+ def output_list_item(self):
+ i_indent = False # initial indent
+ s_indent = True # subsequent indent
+ indent = ''.ljust(self.token['spaces'])
+
+ def process():
+ nonlocal i_indent
+
+ txt = ''
+ if self.token['type'] == 'text':
+ txt = self.renderer.tw_fill(self.tok_text())
+ else:
+ txt = self.tok()
+
+ if not i_indent:
+ txt = txt.lstrip()
+
+ # Set initial indent after processing first item
+ i_indent = True
+ self._add_prefix(indent, i_indent, s_indent)
+
+ return txt
+
+ # Add bullet
+ body = self.renderer.tw_get('initial_indent') + self.token['text']
+
+ # Set prefix
+ prefix = self._add_prefix(indent, i_indent, s_indent)
+
+ # Process list item
+ while self.pop()['type'] != 'list_item_end':
+ body += process()
+
+ # Render list item
+ rendered_li = self.renderer.list_item(body)
+
+ # Remove prefix
+ self._remove_prefix(len(indent), i_indent, s_indent)
+
+ return rendered_li
+
def main():
print('USAGE: md_tw 72 file.md file2.md [...]')