markdown-textwrap

text wrap markdown documents
git clone git://git.ricketyspace.net/markdown-textwrap.git
Log | Files | Refs

commit 910df833d986dc1915fb40e784ec2e143b915c22
parent 3822bf22e4028fa6410e51b0715e664927643563
Author: rsiddharth <s@ricketyspace.net>
Date:   Mon,  5 Mar 2018 02:34:47 +0000

md_tw.py: Add TWMarkdown.output_footnote.

* md_tw.py (TWMarkdown)[output_footnote]: New method.

Diffstat:
md_tw.py | 47+++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+), 0 deletions(-)

diff --git 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 [...]')