summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/data/blexer-block-html.md22
-rw-r--r--tests/test_md_tw.py74
2 files changed, 96 insertions, 0 deletions
diff --git a/tests/data/blexer-block-html.md b/tests/data/blexer-block-html.md
new file mode 100644
index 0000000..edc452d
--- /dev/null
+++ b/tests/data/blexer-block-html.md
@@ -0,0 +1,22 @@
+This is a regular paragraph.
+
+<table>
+ <tr>
+ <td>Monte Carlo</td>
+ </tr>
+</table>
+
+This is another regular paragraph, which is followed by some HTML
+fluff decorated with attributes.
+
+<div class="parley">
+ <article>
+ <p>A dispute conference; human snafu.</p>
+ </article>
+</div>
+
+Which is followed by a
+
+<hr />
+
+Ameba.
diff --git a/tests/test_md_tw.py b/tests/test_md_tw.py
index 6eb769f..18fb1ac 100644
--- a/tests/test_md_tw.py
+++ b/tests/test_md_tw.py
@@ -577,6 +577,80 @@ class TestTWBlockLexer(object):
}
tokens = process(tokens)
+ def test_parse_block_html(self):
+ tokens = self._parse('blexer-block-html.md')
+
+ def process(tokens):
+ token = tokens.pop(0)
+ while token:
+ type_ = token['type']
+
+ expected_token = None
+ if type_ in expected:
+ expected_token = expected[type_].pop(0)
+
+ validate(token, expected_token)
+
+ if type_ in ['open_html', 'close_html']:
+ break
+ else:
+ token = tokens.pop(0)
+
+ return tokens
+
+ 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:
+ assert_equal(token['text'], expected_token['text'])
+ if 'extra' in token:
+ assert_equal(token['extra'], expected_token['extra'])
+ if 'tag' in token:
+ assert_equal(token['tag'], expected_token['tag'])
+ return
+
+ expected = {
+ 'open_html': [
+ {
+ 'tag': 'table',
+ 'extra': '',
+ 'text': '\n <tr>\n <td>Monte Carlo</td>'
+ '\n </tr>\n'
+ },
+ ],
+ }
+ tokens = process(tokens)
+
+ expected = {
+ 'open_html': [
+ {
+ 'tag': 'div',
+ 'extra': ' class="parley"',
+ 'text': '\n <article>\n '
+ '<p>A dispute conference; human snafu.</p>\n '
+ '</article>\n'
+ }
+ ],
+ }
+ tokens = process(tokens)
+
+ expected = {
+ 'close_html': [
+ {'text': '<hr />\n\n'}
+ ]
+ }
+ tokens = process(tokens)
+
def teardown(self):
pass