From 6037043e01b2a096d39883f9f7dd27cdcfe8d0ab Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 22 Feb 2018 14:15:07 +0000 Subject: Markdown: add support for reference-style links --- pygments/lexers/markup.py | 5 +++++ tests/examplefiles/example.md | 3 +++ 2 files changed, 8 insertions(+) diff --git a/pygments/lexers/markup.py b/pygments/lexers/markup.py index 92dc9e7a..6b104bbe 100644 --- a/pygments/lexers/markup.py +++ b/pygments/lexers/markup.py @@ -583,6 +583,11 @@ class MarkdownLexer(RegexLexer): (r'[@#][\w/:]+', Name.Entity), # (image?) links eg: ![Image of Yaktocat](https://octodex.github.com/images/yaktocat.png) (r'(!?\[)([^]]+)(\])(\()([^)]+)(\))', bygroups(Text, Name.Tag, Text, Text, Name.Attribute, Text)), + # reference-style links, e.g.: + # [an example][id] + # [id]: http://example.com/ + (r'(\[)([^]]+)(\])(\[)([^]]*)(\])', bygroups(Text, Name.Tag, Text, Text, Name.Label, Text)), + (r'^(\s*\[)([^]]*)(\]:\s*)(.+)', bygroups(Text, Name.Label, Text, Name.Attribute)), # general text, must come last! (r'[^\\\s]+', Text), diff --git a/tests/examplefiles/example.md b/tests/examplefiles/example.md index 2befb107..e2bbacf1 100644 --- a/tests/examplefiles/example.md +++ b/tests/examplefiles/example.md @@ -46,6 +46,9 @@ this sentence @tweets a person about a #topic. [google](https://google.com/some/path.html) ![Image of Yaktocat](https://octodex.github.com/images/yaktocat.png) +[reference link][id] +[id]: http://example.com/ + ``` * this is just unformated __text__ -- cgit v1.2.1