markdown-textwrap

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

commit d9d4e31636da136be3a8dd60d507140e03c0cf6c
parent 9df739fcf2e837d0131c8d468564b46f8c7adb98
Author: rsiddharth <s@ricketyspace.net>
Date:   Tue,  2 Jan 2018 00:34:32 +0000

md_tw.py: Add `TWBlockLexer.parse_block_code`.

* md_tw.py
(TWBlockLexer.parse_block_code): New method.
* tests/test_md_tw.py
(TestTWBlockLexer._parse)
(TestTWBlockLexer._validate): New private methods.
(TestTWBlockLexer.test_parse_block_code): New test.
* tests/data/blexer-block-code.md: New file.

Diffstat:
md_tw.py | 7+++++++
tests/data/blexer-block-code.md | 10++++++++++
tests/test_md_tw.py | 19+++++++++++++++++--
3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/md_tw.py b/md_tw.py @@ -38,6 +38,13 @@ class TWBlockLexer(mistune.BlockLexer): key = mistune.escape(key.lower(), quote=True) return self._key_pattern.sub(' ', key) + def parse_block_code(self, m): + self.tokens.append({ + 'type': 'code', + 'lang': None, + 'text': m.group(0), + }) + class TWInlineLexer(mistune.InlineLexer): """Text Wrap Inline level lexer for inline gramars.""" diff --git a/tests/data/blexer-block-code.md b/tests/data/blexer-block-code.md @@ -0,0 +1,10 @@ +Let's have some chaos: + + $ echo 'Zap!' + $ rm -rf / + +> Some Jaromil art inside a block quote +> +> $ :(){:|:&};: +> +> For more look at jaramil.dyne.org. He's awesome. diff --git a/tests/test_md_tw.py b/tests/test_md_tw.py @@ -40,8 +40,23 @@ class TestTWBlockLexer(object): def setup(self): self.bl = TWBlockLexer() - - + def _parse(self, file_): + txt = _get_data(file_) + return self.bl.parse(txt) + + def _validate(self, tokens, type_, expected): + for token in tokens: + if token['type'] == type_: + assert_equal(token['text'], expected.pop(0)) + + def test_parse_block_code(self): + tokens = self._parse('blexer-block-code.md') + + expected_bc = [ + ' $ echo \'Zap!\'\n $ rm -rf /\n\n', + ' $ :(){:|:&};:\n\n' + ] + self._validate(tokens, 'code', expected_bc) def teardown(self): pass