markdown-textwrap

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

commit d78ac3764a90fc959862777f37fc9f175e5272e1
parent 06fd732f8d1b4b1d6ef7313df8f441009c781cd7
Author: rsiddharth <s@ricketyspace.net>
Date:   Tue,  2 Jan 2018 00:41:45 +0000

md_tw.py: Add TWBlockLexer.parse_lheading.

* md_tw.py
(TWBlockLexer.parse_lheading): New method.
* tests/test_md_tw.py
(TestTWBlockLexer.test_parse_lheading): New method.
* tests/data/blexer-lheading.md: New file.

Diffstat:
md_tw.py | 8++++++++
tests/data/blexer-lheading.md | 13+++++++++++++
tests/test_md_tw.py | 11+++++++++++
3 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/md_tw.py b/md_tw.py @@ -59,6 +59,14 @@ class TWBlockLexer(mistune.BlockLexer): 'text': m.group(0), }) + def parse_lheading(self, m): + """Parse setext heading.""" + self.tokens.append({ + 'type': 'heading', + 'level': 1 if m.group(2) == '=' else 2, + 'text': m.group(0), + }) + class TWInlineLexer(mistune.InlineLexer): """Text Wrap Inline level lexer for inline gramars.""" diff --git a/tests/data/blexer-lheading.md b/tests/data/blexer-lheading.md @@ -0,0 +1,13 @@ +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 @@ -79,6 +79,17 @@ class TestTWBlockLexer(object): self._validate(tokens, 'heading', expected_hs) + def test_parse_lheading(self): + tokens = self._parse('blexer-lheading.md') + + expected_lhs = [ + 'Milky Chance\n============\n\n', + 'Flashed\n-------\n\n', + '### Junk Mind\n\n', + ] + + self._validate(tokens, 'heading', expected_lhs) + def teardown(self): pass