diff options
author | rsiddharth <s@ricketyspace.net> | 2018-01-02 00:47:30 +0000 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2018-01-02 00:47:30 +0000 |
commit | 12903a82dc2ee039b0356855657e3f66173b9e92 (patch) | |
tree | 1b6e159c8be7d9270092e6648d0b946e91108bcf /md_tw.py | |
parent | 9011ef7c4e768955bd3a4355d86eda39469bc127 (diff) |
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.
Diffstat (limited to 'md_tw.py')
-rw-r--r-- | md_tw.py | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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.""" |