From 65d6566b2ac5ca23c87179e24fa9bd4c14173ea4 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 29 Nov 2007 20:58:03 +0000 Subject: Added support for images inside links and updated tests. Fixes [1458136]. Note, to accomplish this, a negative lookbehind (for a !) was added to each link regex so they could be run before the image regex. The (fairly new) recursion on the link text then parses the image. Not sure how the negative lookbehind will affect performance. --- markdown.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'markdown.py') diff --git a/markdown.py b/markdown.py index 99f76b8..cc657c8 100644 --- a/markdown.py +++ b/markdown.py @@ -655,6 +655,7 @@ BRK = ( r'\[(' + (NOBRACKET + r'(\[')*6 + (NOBRACKET+ r'\])*')*6 + NOBRACKET + r')\]' ) +NOIMG = r'(?\)' # [text]() +LINK_RE = NOIMG + BRK + r'\s*\(([^\)]*)\)' # [text](url) +LINK_ANGLED_RE = NOIMG + BRK + r'\s*\(<([^\)]*)>\)' # [text]() IMAGE_LINK_RE = r'\!' + BRK + r'\s*\(([^\)]*)\)' # ![alttxt](http://x.com/) -REFERENCE_RE = BRK+ r'\s*\[([^\]]*)\]' # [Google][3] +REFERENCE_RE = NOIMG + BRK+ r'\s*\[([^\]]*)\]' # [Google][3] IMAGE_REFERENCE_RE = r'\!' + BRK + '\s*\[([^\]]*)\]' # ![alt text][2] NOT_STRONG_RE = r'( \* )' # stand-alone * or _ AUTOLINK_RE = r'<(http://[^>]*)>' # @@ -1150,12 +1151,12 @@ class Markdown: self.inlinePatterns = [DOUBLE_BACKTICK_PATTERN, BACKTICK_PATTERN, ESCAPE_PATTERN, - IMAGE_LINK_PATTERN, - IMAGE_REFERENCE_PATTERN, REFERENCE_PATTERN, LINK_ANGLED_PATTERN, LINK_PATTERN, - AUTOLINK_PATTERN, + IMAGE_LINK_PATTERN, + IMAGE_REFERENCE_PATTERN, + AUTOLINK_PATTERN, AUTOMAIL_PATTERN, LINE_BREAK_PATTERN_2, LINE_BREAK_PATTERN, -- cgit v1.2.3