markdown-textwrap

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

commit 06fd732f8d1b4b1d6ef7313df8f441009c781cd7
parent a18df9d9adc54bbc8ea1f3b1a1c59f316667e840
Author: rsiddharth <s@ricketyspace.net>
Date:   Tue,  2 Jan 2018 00:39:27 +0000

md_tw: Add TWBlockLexer.parse_heading.

* md_tw.py
(TWBlockLexer.parse_heading): New method.
* tests/data/blexer-heading.md: New file.
* tests/test_md_tw.py
(TestTWBlockLexer.test_parse_heading): New test.

Diffstat:
md_tw.py | 7+++++++
tests/data/blexer-heading.md | 11+++++++++++
tests/test_md_tw.py | 11+++++++++++
3 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/md_tw.py b/md_tw.py @@ -52,6 +52,13 @@ class TWBlockLexer(mistune.BlockLexer): 'text': m.group(0), }) + def parse_heading(self, m): + self.tokens.append({ + 'type': 'heading', + 'level': len(m.group(1)), + 'text': m.group(0), + }) + class TWInlineLexer(mistune.InlineLexer): """Text Wrap Inline level lexer for inline gramars.""" diff --git a/tests/data/blexer-heading.md b/tests/data/blexer-heading.md @@ -0,0 +1,11 @@ +# Milky Chance + +Clemens, Phillipp, Antonio + +## Flashed + +Lost our mind. + +### Junk Mind + +In the junkyard. diff --git a/tests/test_md_tw.py b/tests/test_md_tw.py @@ -68,6 +68,17 @@ class TestTWBlockLexer(object): self._validate(tokens, 'code', expected_fences) + def test_parse_heading(self): + tokens = self._parse('blexer-heading.md') + + expected_hs = [ + '# Milky Chance\n\n', + '## Flashed\n\n', + '### Junk Mind\n\n', + ] + + self._validate(tokens, 'heading', expected_hs) + def teardown(self): pass