summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2018-02-19 05:11:54 +0000
committerrsiddharth <s@ricketyspace.net>2018-02-19 05:11:54 +0000
commit911cd0ee97854e512ab8d8ecf5faaa92a063864e (patch)
treef478d5d40fd145aac8420c75c38afa6bcd48e5d9
parentc65420d1518032fdf20fdeb5030f6b27598c2486 (diff)
md_tw.py: Add TWMarkdown.output_loose_item.
* md_tw.py (TWMarkdown)[output_loose_item]: New method.
-rw-r--r--md_tw.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/md_tw.py b/md_tw.py
index 2b3f357..d2489f2 100644
--- a/md_tw.py
+++ b/md_tw.py
@@ -396,6 +396,41 @@ class TWMarkdown(mistune.Markdown):
return rendered_li
+ def output_loose_item(self):
+ i_indent = False # initial indent
+ s_indent = True # subsequent indent
+ indent = ''.ljust(self.token['spaces'])
+
+ def process():
+ nonlocal i_indent
+
+ 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)
+
+ while self.pop()['type'] != 'list_item_end':
+ body += process()
+ body = body.rstrip() + '\n'
+
+ 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 [...]')