فهرست منبع

fix(image-parser): fix ref style imgs after inline style imgs not parsing correctly

When reference style and inline style are mixed together, in the same line, it produces weird parsing bugs. This commit fixes this

Closes #261
Estevão Soares dos Santos 9 سال پیش
والد
کامیت
73206b07fb

+ 6 - 2
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown 17-05-2016 */
+;/*! showdown 08-06-2016 */
 (function(){
 /**
  * Created by Tivie on 13-07-2015.
@@ -1424,6 +1424,10 @@ showdown.subParser('codeSpans', function (text, options, globals) {
    (?!`)
    /gm, function(){...});
    */
+
+  if (typeof(text) === 'undefined') {
+    text = '';
+  }
   text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
     function (wholeMatch, m1, m2, m3) {
       var c = m3;
@@ -1875,7 +1879,7 @@ showdown.subParser('images', function (text, options, globals) {
   text = globals.converter._dispatch('images.before', text, options, globals);
 
   var inlineRegExp    = /!\[(.*?)]\s?\([ \t]*()<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,
-      referenceRegExp = /!\[(.*?)][ ]?(?:\n[ ]*)?\[(.*?)]()()()()()/g;
+      referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[(.*?)]()()()()()/g;
 
   function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
 

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/showdown.js.map


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/showdown.min.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/showdown.min.js.map


+ 1 - 1
src/subParsers/images.js

@@ -7,7 +7,7 @@ showdown.subParser('images', function (text, options, globals) {
   text = globals.converter._dispatch('images.before', text, options, globals);
 
   var inlineRegExp    = /!\[(.*?)]\s?\([ \t]*()<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,
-      referenceRegExp = /!\[(.*?)][ ]?(?:\n[ ]*)?\[(.*?)]()()()()()/g;
+      referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[(.*?)]()()()()()/g;
 
   function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
 

+ 17 - 0
test/issues/#261.mix-images-with-links.html

@@ -0,0 +1,17 @@
+<p><img src="https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png" alt="sd-inline" /> <a href="https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">sd-ref</a></p>
+
+<p>foo</p>
+
+<p><a href="https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png">sd-inline</a> <img src="https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" alt="sd-ref" /></p>
+
+<p>foo</p>
+
+<p><img src="https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" alt="sd-ref" /> <a href="https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png">sd-inline</a></p>
+
+<p>foo</p>
+
+<p><a href="https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">sd-ref</a> <img src="https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png" alt="sd-inline" /></p>
+
+<p>foo</p>
+
+<p><a href="http://www.google.com/"><img src="https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" alt="sd-ref" /></a></p>

+ 19 - 0
test/issues/#261.mix-images-with-links.md

@@ -0,0 +1,19 @@
+![sd-inline](https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png) [sd-ref][sd-logo]
+
+foo
+
+[sd-inline](https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png) ![sd-ref][sd-logo]
+
+foo
+
+![sd-ref][sd-logo] [sd-inline](https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png)
+
+foo
+
+[sd-ref][sd-logo] ![sd-inline](https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png)
+
+foo
+
+[![sd-ref][sd-logo]](http://www.google.com/)
+
+[sd-logo]: https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png

+ 5 - 0
test/issues/#261.reference-style-image-after-inline-style-image-does-not-work-correctely.html

@@ -0,0 +1,5 @@
+<p><img src="https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png" alt="sd-inline" /> <img src="https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" alt="sd-ref" /></p>
+
+<p>foo</p>
+
+<p><img src="https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" alt="sd-ref" /> <img src="https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png" alt="sd-inline" /></p>

+ 7 - 0
test/issues/#261.reference-style-image-after-inline-style-image-does-not-work-correctely.md

@@ -0,0 +1,7 @@
+![sd-inline](https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png) ![sd-ref][sd-logo]
+
+foo
+
+![sd-ref][sd-logo] ![sd-inline](https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png)
+
+[sd-logo]: https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png

+ 5 - 0
test/issues/#261.reference-style-link-after-inline-style-link-does-not-work-correctely.html

@@ -0,0 +1,5 @@
+<p><a href="https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png">sd-inline</a> <a href="https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">sd-ref</a></p>
+
+<p>foo</p>
+
+<p><a href="https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">sd-ref</a> <a href="https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png">sd-inline</a></p>

+ 7 - 0
test/issues/#261.reference-style-link-after-inline-style-link-does-not-work-correctely.md

@@ -0,0 +1,7 @@
+[sd-inline](https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png) [sd-ref][sd-logo]
+
+foo
+
+[sd-ref][sd-logo] [sd-inline](https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png)
+
+[sd-logo]: https://www.google.pt/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است