summaryrefslogtreecommitdiffstats
path: root/md_tw.py
diff options
context:
space:
mode:
Diffstat (limited to 'md_tw.py')
-rw-r--r--md_tw.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/md_tw.py b/md_tw.py
index 7f9b578..352805f 100644
--- a/md_tw.py
+++ b/md_tw.py
@@ -159,6 +159,48 @@ class TWBlockLexer(mistune.BlockLexer):
'text': m.group(0)
})
+ def parse_def_footnotes(self, m):
+ key = self._keyify(m.group(1))
+ if key in self.def_footnotes:
+ # footnote is already defined
+ return
+
+ self.def_footnotes[key] = 0
+
+ text = m.group(2)
+ multiline = False
+ spaces = 0
+ if '\n' in text:
+ multiline = True
+ lines = text.split('\n')
+ whitespace = None
+ for line in lines[1:]:
+ space = len(line) - len(line.lstrip())
+ if space and (not whitespace or space < whitespace):
+ whitespace = space
+ newlines = [lines[0]]
+ for line in lines[1:]:
+ newlines.append(line[whitespace:])
+ text = '\n'.join(newlines)
+
+ if whitespace:
+ spaces = whitespace
+
+ self.tokens.append({
+ 'type': 'footnote_start',
+ 'key': key,
+ 'multiline': multiline,
+ 'spaces': spaces
+ })
+
+ self.parse(text, self.footnote_rules)
+
+ self.tokens.append({
+ 'type': 'footnote_end',
+ 'key': key,
+ 'spaces': spaces
+ })
+
class TWInlineLexer(mistune.InlineLexer):
"""Text Wrap Inline level lexer for inline gramars."""