summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--md_tw.py11
-rw-r--r--tests/data/blexer-def-links.md34
-rw-r--r--tests/test_md_tw.py17
3 files changed, 62 insertions, 0 deletions
diff --git a/md_tw.py b/md_tw.py
index 19b5b30..7f9b578 100644
--- a/md_tw.py
+++ b/md_tw.py
@@ -148,6 +148,17 @@ class TWBlockLexer(mistune.BlockLexer):
'spaces': len(quote)
})
+ def parse_def_links(self, m):
+ key = self._keyify(m.group(1))
+ self.def_links[key] = {
+ 'link': m.group(2),
+ 'title': m.group(3),
+ }
+ self.tokens.append({
+ 'type': 'def_links',
+ 'text': m.group(0)
+ })
+
class TWInlineLexer(mistune.InlineLexer):
"""Text Wrap Inline level lexer for inline gramars."""
diff --git a/tests/data/blexer-def-links.md b/tests/data/blexer-def-links.md
new file mode 100644
index 0000000..c09e417
--- /dev/null
+++ b/tests/data/blexer-def-links.md
@@ -0,0 +1,34 @@
+This is [an example](http://example.com/ "Title") inline link.
+
+[This link](http://example.net/) has no title attribute.
+
+See my [About](/about/) page for details.
+
+This is [Bob][bob]'s web space.
+
+This is [Alice][alice]'s web space.
+
+[bob]: http://bob.name/ "Bob's home"
+[alice]: <http://alice.name/> "Alice's home"
+
+Some foo[bar].
+
+[bar]: http://bar.beer/ "Foo Bar Beer"
+
+Visit [GNU.org][].
+
+[GNU.org]: http://gnu.org
+
+John Gruber gets 10 times more traffic from [Google][1] than from
+[Yahoo][2] or [MSN][3].
+
+ [1]: http://google.com/ "Google"
+ [2]: http://search.yahoo.com/ "Yahoo Search"
+ [3]: http://search.msn.com/ "MSN Search"
+
+John Gruber gets 10 times more traffic from [Google][] than from
+[Yahoo][] or [MSN][].
+
+ [google]: http://google.com/ "Google"
+ [yahoo]: http://search.yahoo.com/ "Yahoo Search"
+ [msn]: http://search.msn.com/ "MSN Search"
diff --git a/tests/test_md_tw.py b/tests/test_md_tw.py
index 4b78dcd..467caaf 100644
--- a/tests/test_md_tw.py
+++ b/tests/test_md_tw.py
@@ -463,6 +463,23 @@ class TestTWBlockLexer(object):
}
tokens = process(tokens)
+ def test_parse_def_links(self):
+ tokens = self._parse('blexer-def-links.md')
+
+ expected_dls = [
+ '[bob]: http://bob.name/ "Bob\'s home"\n',
+ '[alice]: <http://alice.name/> "Alice\'s home"\n\n',
+ '[bar]: http://bar.beer/ "Foo Bar Beer"\n\n',
+ '[GNU.org]: http://gnu.org\n\n',
+ ' [1]: http://google.com/ "Google"\n',
+ ' [2]: http://search.yahoo.com/ "Yahoo Search"\n',
+ ' [3]: http://search.msn.com/ "MSN Search"\n\n',
+ ' [google]: http://google.com/ "Google"\n',
+ ' [yahoo]: http://search.yahoo.com/ "Yahoo Search"\n',
+ ' [msn]: http://search.msn.com/ "MSN Search"',
+ ]
+ self._validate(tokens, 'def_links', expected_dls)
+
def teardown(self):
pass