summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2018-03-05 02:34:47 +0000
committerrsiddharth <s@ricketyspace.net>2018-03-05 02:34:47 +0000
commit910df833d986dc1915fb40e784ec2e143b915c22 (patch)
tree23a299b87702c95c65b0eb30a27cef57f5cd025c
parent3822bf22e4028fa6410e51b0715e664927643563 (diff)
md_tw.py: Add TWMarkdown.output_footnote.
* md_tw.py (TWMarkdown)[output_footnote]: New method.
-rw-r--r--md_tw.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/md_tw.py b/md_tw.py
index ba85ea0..458e6c0 100644
--- a/md_tw.py
+++ b/md_tw.py
@@ -467,6 +467,53 @@ class TWMarkdown(mistune.Markdown):
def output_def_link(self):
return self.renderer.def_link(self.token['text'])
+ def output_footnote(self):
+ rm_i_indent = True
+ indent = ''.ljust(self.token['spaces'])
+
+ def process():
+ nonlocal rm_i_indent
+
+ txt = self.tok()
+ if rm_i_indent:
+ txt = txt.lstrip()
+
+ # Don't remove initial indent after processing first item.
+ rm_i_indent = False
+
+ return txt
+
+ # Take note of footnote key.
+ key = self.token['key']
+
+ # Add current initial indent
+ body = self.renderer.tw_get('initial_indent')
+
+ # Set width
+ o_width = self.renderer.tw_get('width')
+ item_width = (o_width
+ - (len(self.renderer.tw_get('initial_indent'))
+ # Account for '[^key]: '
+ + (len(key) + 5)))
+ self.renderer.tw_set(width=item_width)
+
+ # Set prefix
+ prefix = self._add_prefix(indent)
+
+ while self.pop()['type'] != 'footnote_end':
+ body += process()
+ body = body.rstrip() + '\n'
+
+ rendered_fn = self.renderer.footnote_item(key, body)
+
+ # Remove prefix
+ self._remove_prefix(len(indent))
+
+ # Revert width
+ self.renderer.tw_set(width=o_width)
+
+ return rendered_fn
+
def main():
print('USAGE: md_tw 72 file.md file2.md [...]')