From 12903a82dc2ee039b0356855657e3f66173b9e92 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Tue, 2 Jan 2018 00:47:30 +0000 Subject: md_tw.py: Add TWBlockLexer.parse_block_quote. * md_tw.py (TWBlockLexer.parse_block_quote): New method. (TWBlockLexer.__init__): Update method. * tests/test_md_tw.py (TestTWBlockLexer.test_parse_block_quote): New test. * tests/data/blexer-blockquote.md: New file. --- md_tw.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'md_tw.py') diff --git a/md_tw.py b/md_tw.py index 7b20692..19b5b30 100644 --- a/md_tw.py +++ b/md_tw.py @@ -31,6 +31,7 @@ class TWBlockLexer(mistune.BlockLexer): super(TWBlockLexer, self).__init__(rules, **kwargs) # from mistune + self._block_quote_leading_pattern = re.compile(r'^ *> ?', flags=re.M) self._key_pattern = re.compile(r'\s+') # from mistune @@ -127,6 +128,26 @@ class TWBlockLexer(mistune.BlockLexer): 'spaces': len(bullet) }) + def parse_block_quote(self, m): + # slurp and clean leading > + quote = '' + qm = self._block_quote_leading_pattern.match(m.group(0)) + if qm: + quote = qm.group(0) + + cap = self._block_quote_leading_pattern.sub('', m.group(0)) + + self.tokens.append({ + 'type': 'block_quote_start', + 'text': quote, + 'spaces': len(quote) + }) + self.parse(cap) + self.tokens.append({ + 'type': 'block_quote_end', + 'spaces': len(quote) + }) + class TWInlineLexer(mistune.InlineLexer): """Text Wrap Inline level lexer for inline gramars.""" -- cgit v1.2.3