aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--markdown.py13
-rw-r--r--tests/markdown-test/benchmark.dat.tmp30
-rw-r--r--tests/misc/benchmark.dat.tmp72
-rw-r--r--tests/misc/image_in_links.html7
-rw-r--r--tests/misc/uche.html11
5 files changed, 64 insertions, 69 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,
diff --git a/tests/markdown-test/benchmark.dat.tmp b/tests/markdown-test/benchmark.dat.tmp
index 80b04cd..5828f9a 100644
--- a/tests/markdown-test/benchmark.dat.tmp
+++ b/tests/markdown-test/benchmark.dat.tmp
@@ -1,20 +1,20 @@
construction:0.000000:0.000000
-amps-and-angle-encoding:0.030000:0.000000
-auto-links:0.030000:0.000000
-backlash-escapes:0.100000:131072.000000
-blockquotes-with-dode-blocks:0.010000:0.000000
-hard-wrapped:0.010000:0.000000
-horizontal-rules:0.080000:0.000000
-inline-html-advanced:0.030000:0.000000
+amps-and-angle-encoding:0.020000:0.000000
+auto-links:0.020000:0.000000
+backlash-escapes:0.110000:131072.000000
+blockquotes-with-dode-blocks:0.000000:0.000000
+hard-wrapped:0.000000:0.000000
+horizontal-rules:0.070000:0.000000
+inline-html-advanced:0.020000:0.000000
inline-html-comments:0.030000:0.000000
inline-html-simple:0.100000:0.000000
links-inline:0.050000:0.000000
-links-reference:0.070000:0.000000
-literal-quotes:0.030000:0.000000
-markdown-documentation-basics:0.340000:823296.000000
-markdown-syntax:1.620000:1568768.000000
-nested-blockquotes:0.050000:-110592.000000
-ordered-and-unordered-list:0.240000:-4096.000000
-strong-and-em-together:0.060000:0.000000
+links-reference:0.090000:0.000000
+literal-quotes:0.040000:0.000000
+markdown-documentation-basics:0.350000:770048.000000
+markdown-syntax:1.790000:1540096.000000
+nested-blockquotes:0.040000:0.000000
+ordered-and-unordered-list:0.240000:-16384.000000
+strong-and-em-together:0.050000:0.000000
tabs:0.060000:0.000000
-tidyness:0.060000:0.000000
+tidyness:0.050000:0.000000
diff --git a/tests/misc/benchmark.dat.tmp b/tests/misc/benchmark.dat.tmp
index fabdd97..4fecb5c 100644
--- a/tests/misc/benchmark.dat.tmp
+++ b/tests/misc/benchmark.dat.tmp
@@ -1,54 +1,54 @@
-construction:0.000000:-24576.000000
+construction:0.000000:0.000000
adjacent-headers:0.010000:0.000000
-amp-in-url:0.000000:0.000000
-ampersand:0.010000:0.000000
-arabic:0.030000:0.000000
+amp-in-url:0.010000:0.000000
+ampersand:0.000000:0.000000
+arabic:0.040000:0.000000
attributes2:0.010000:0.000000
-bidi:0.090000:-57344.000000
+bidi:0.080000:0.000000
blank:0.000000:0.000000
-blank-block-quote:0.010000:0.000000
+blank-block-quote:0.000000:0.000000
blockquote-hr:0.020000:0.000000
-br:0.030000:0.000000
-bracket_re:1.580000:0.000000
-code-first-line:0.000000:0.000000
-comments:0.020000:0.000000
-div:0.030000:0.000000
-email:0.030000:0.000000
-funky-list:0.050000:0.000000
-h1:0.030000:0.000000
-hash:0.030000:0.000000
-headers:0.030000:0.000000
-hline:0.010000:0.000000
-html:0.040000:0.000000
+br:0.020000:0.000000
+bracket_re:1.230000:0.000000
+code-first-line:0.010000:0.000000
+comments:0.010000:0.000000
+div:0.010000:0.000000
+email:0.010000:0.000000
+funky-list:0.020000:0.000000
+h1:0.010000:0.000000
+hash:0.020000:0.000000
+headers:0.020000:0.000000
+hline:0.020000:0.000000
+html:0.030000:0.000000
image:0.010000:0.000000
-image-2:0.020000:0.000000
-image_in_links:0.010000:0.000000
-inside_html:0.010000:0.000000
+image-2:0.010000:0.000000
+image_in_links:0.020000:0.000000
+inside_html:0.020000:0.000000
japanese:0.050000:0.000000
-lazy-block-quote:0.010000:0.000000
-lists:0.040000:0.000000
+lazy-block-quote:0.020000:0.000000
+lists:0.050000:0.000000
lists2:0.020000:0.000000
-lists3:0.020000:0.000000
+lists3:0.010000:0.000000
lists4:0.020000:0.000000
-lists5:0.030000:0.000000
+lists5:0.010000:0.000000
markup-inside-p:0.020000:0.000000
mismatched-tags:0.020000:0.000000
-more_comments:0.020000:0.000000
+more_comments:0.010000:0.000000
multi-line-tags:0.030000:0.000000
multi-paragraph-block-quote:0.020000:0.000000
multi-test:0.050000:0.000000
-multiline-comments:0.030000:0.000000
+multiline-comments:0.020000:0.000000
normalize:0.020000:0.000000
-numeric-entity:0.020000:0.000000
+numeric-entity:0.030000:0.000000
php:0.030000:0.000000
pre:0.030000:0.000000
-russian:0.070000:0.000000
-some-test:0.080000:0.000000
-span:0.050000:0.000000
-stronintags:0.040000:0.000000
-tabs-in-lists:0.060000:0.000000
+russian:0.070000:-12288.000000
+some-test:0.090000:0.000000
+span:0.040000:0.000000
+stronintags:0.050000:0.000000
+tabs-in-lists:0.070000:0.000000
two-spaces:0.060000:0.000000
-uche:0.040000:0.000000
-underscores:0.050000:0.000000
+uche:0.050000:0.000000
+underscores:0.040000:0.000000
url_spaces:0.030000:0.000000
-utfbom:0.030000:0.000000
+utfbom:0.020000:0.000000
diff --git a/tests/misc/image_in_links.html b/tests/misc/image_in_links.html
index fde1416..e2027b5 100644
--- a/tests/misc/image_in_links.html
+++ b/tests/misc/image_in_links.html
@@ -1,5 +1,2 @@
-
-<p>[<img src="path/to/img_thumb.png" alt="altname"/>](path/to/image.png)
-</p>
-
-
+<p><a href="path/to/image.png"><img src="path/to/img_thumb.png" alt="altname"/></a>
+</p> \ No newline at end of file
diff --git a/tests/misc/uche.html b/tests/misc/uche.html
index e6c725b..f438f3d 100644
--- a/tests/misc/uche.html
+++ b/tests/misc/uche.html
@@ -1,10 +1,7 @@
-
<p><img src="http://fourthought.com/images/ftlogo.png" title="Fourthought logo" alt="asif"/>
</p>
-<p>[<img src="http://fourthought.com/images/ftlogo.png" title="Fourthought logo" style="float: left; margin: 10px; border:
-none;" alt=""/>](http://fourthought.com/)
+<p><a href="http://fourthought.com/"><img src="http://fourthought.com/images/ftlogo.png" title="Fourthought logo" style="float: left; margin: 10px; border:
+none;" alt=""/></a>
</p>
-<p>[<img src="x" alt="text"/>](http://link.com/)
-</p>
-
-
+<p><a href="http://link.com/"><img src="x" alt="text"/></a>
+</p> \ No newline at end of file