aboutsummaryrefslogtreecommitdiffstats
path: root/markdown.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2007-11-29 20:58:03 +0000
committerWaylan Limberg <waylan@gmail.com>2007-11-29 20:58:03 +0000
commit65d6566b2ac5ca23c87179e24fa9bd4c14173ea4 (patch)
tree3b207a94b23b909bd93e2dc1f229c02ffe4fb397 /markdown.py
parent9f8372ece0b824e2038a7b728064ae454283db68 (diff)
downloadmarkdown-65d6566b2ac5ca23c87179e24fa9bd4c14173ea4.tar.gz
markdown-65d6566b2ac5ca23c87179e24fa9bd4c14173ea4.tar.bz2
markdown-65d6566b2ac5ca23c87179e24fa9bd4c14173ea4.zip
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.
Diffstat (limited to 'markdown.py')
-rw-r--r--markdown.py13
1 files changed, 7 insertions, 6 deletions
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'(?<!\!)'
BACKTICK_RE = r'\`([^\`]*)\`' # `e= m*c^2`
DOUBLE_BACKTICK_RE = r'\`\`(.*)\`\`' # ``e=f("`")``
@@ -671,10 +672,10 @@ else:
STRONG_2_RE = r'__([^_]*)__' # __strong__
STRONG_EM_2_RE = r'___([^_]*)___' # ___strong___
-LINK_RE = BRK + r'\s*\(([^\)]*)\)' # [text](url)
-LINK_ANGLED_RE = BRK + r'\s*\(<([^\)]*)>\)' # [text](<url>)
+LINK_RE = NOIMG + BRK + r'\s*\(([^\)]*)\)' # [text](url)
+LINK_ANGLED_RE = NOIMG + BRK + r'\s*\(<([^\)]*)>\)' # [text](<url>)
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://[^>]*)>' # <http://www.123.com>
@@ -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,