Permalink
Browse files

Images must be parsed before inline shorthand

  • Loading branch information...
1 parent baca595 commit 3a27a3944e728dc09fa682e3d077b685c7511224 Alex Young committed Aug 11, 2011
Showing with 8 additions and 2 deletions.
  1. +2 −2 lib/stextile.js
  2. +6 −0 test/test.js
View
@@ -300,10 +300,10 @@ Textile.prototype = {
inline: function(text) {
text = this.links(text);
+ text = text.replace(/!(([:alnum:]|\/|\?)[^!\s]+)\((.*)\)!?(?![^<]*>)/g, '<img src="$1" alt="$3" />');
+ text = text.replace(/!(([:alnum:]|\/|\?)[^!\s]+)!(?![^<]*>)/g, '<img src="$1" alt="" />');
text = text.replace(/\*([^*]*)\*(?![^<]*<\/)(?![^<]*>)/g, '<strong>$1</strong>');
text = text.replace(/_([^_]*)_(?![^<]*<\/)(?![^<]*>)/g, '<em>$1</em>');
- text = text.replace(/!(([:alnum:]|\/|\?)[^!\s]+)\((.*)\)!?(?![^<]*<\/([a-zA-Z]))/g, '<img src="$1" alt="$3" />');
- text = text.replace(/!(([:alnum:]|\/|\?)[^!\s]+)!(?![^<]*>)/g, '<img src="$1" alt="" />');
text = this.replaceEntities(text);
return text;
View
@@ -93,6 +93,12 @@ assert.equal(
textile('"!/images/test-thumb.png!":/images/test.png')
);
+// Images with things that look like em/strong shorthand -- the trick is to parse images first
+assert.equal(
+ '<p><img src="/images/constants_are_changing.png" alt="" /></p>\n',
+ textile('!/images/constants_are_changing.png!')
+);
+
// Multiple images
assert.equal('<p><img src="/images/posts/cluster_live.png" alt="" /></p>\n<p>More text</p>\n<p><img src="/example.png" alt="" /></p>\n', textile('!/images/posts/cluster_live.png!\nMore text\n!/example.png!'));

0 comments on commit 3a27a39

Please sign in to comment.