markdown-textwrap

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

commit 6d34500e55eb225a89d26ed7606a772c638b6984
parent b6a4d7a645c784b7bd3f6d64298d7b9047cf22c3
Author: rsiddharth <s@ricketyspace.net>
Date:   Sun, 18 Feb 2018 20:18:52 +0000

md_tw.py: Add TWBlockLexer.parse_block_html.

* md_tw.py (TWBlockLexer)[parse_block_html]: New method.
* tests/test_md_tw.py (TestTWBlockLexer)
[test_parse_block_html]: Update test method.

Diffstat:
md_tw.py | 6++++++
tests/test_md_tw.py | 31++++++++-----------------------
2 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/md_tw.py b/md_tw.py @@ -201,6 +201,12 @@ class TWBlockLexer(mistune.BlockLexer): 'spaces': spaces }) + def parse_block_html(self, m): + self.tokens.append({ + 'type': 'block_html', + 'text': m.group(0) + }) + class TWInlineLexer(mistune.InlineLexer): """Text Wrap Inline level lexer for inline gramars.""" diff --git a/tests/test_md_tw.py b/tests/test_md_tw.py @@ -594,7 +594,7 @@ class TestTWBlockLexer(object): validate(token, expected_token) - if type_ in ['open_html', 'close_html']: + if type_ == 'block_html': break else: token = tokens.pop(0) @@ -604,51 +604,36 @@ class TestTWBlockLexer(object): def validate(token, expected_token=None): type_ = token['type'] - if type_ == 'open_html': - assert 'tag' in token - assert 'extra' in token - assert 'text' in token - elif type_ == 'close_html': - assert 'text' in token - if not expected_token: return if 'text' in token: nose_tools.assert_equal(token['text'], expected_token['text']) - if 'extra' in token: - nose_tools.assert_equal(token['extra'], expected_token['extra']) - if 'tag' in token: - nose_tools.assert_equal(token['tag'], expected_token['tag']) return expected = { - 'open_html': [ + 'block_html': [ { - 'tag': 'table', - 'extra': '', - 'text': '\n <tr>\n <td>Monte Carlo</td>' - '\n </tr>\n' + 'text': '<table>\n <tr>\n <td>Monte Carlo</td>' + '\n </tr>\n</table>\n\n' }, ], } tokens = process(tokens) expected = { - 'open_html': [ + 'block_html': [ { - 'tag': 'div', - 'extra': ' class="parley"', - 'text': '\n <article>\n ' + 'text': '<div class="parley">\n <article>\n ' '<p>A dispute conference; human snafu.</p>\n ' - '</article>\n' + '</article>\n</div>\n\n' } ], } tokens = process(tokens) expected = { - 'close_html': [ + 'block_html': [ {'text': '<hr />\n\n'} ] }