فهرست منبع

feat(images): add support for image's implicit reference syntax

Closes #366
Estevao Soares dos Santos 8 سال پیش
والد
کامیت
0c6c07b341

+ 8 - 3
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown 15-03-2017 */
+;/*! showdown 30-03-2017 */
 (function(){
 /**
  * Created by Tivie on 13-07-2015.
@@ -259,6 +259,7 @@ showdown.setFlavor = function (name) {
   if (!flavor.hasOwnProperty(name)) {
     throw Error(name + ' flavor was not found');
   }
+  showdown.resetOptions();
   var preset = flavor[name];
   setFlavor = name;
   for (var option in preset) {
@@ -2106,8 +2107,9 @@ 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;
+  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,
+      refShortcutRegExp = /!\[([^\[\]]+)]()()()()()/g;
 
   function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
 
@@ -2177,6 +2179,9 @@ showdown.subParser('images', function (text, options, globals) {
   // Next, handle inline images:  ![alt text](url =<width>x<height> "optional title")
   text = text.replace(inlineRegExp, writeImageTag);
 
+  // handle reference-style shortcuts: |[img text]
+  text = text.replace(refShortcutRegExp, writeImageTag);
+
   text = globals.converter._dispatch('images.after', text, options, globals);
   return text;
 });

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


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


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


+ 6 - 2
src/subParsers/images.js

@@ -6,8 +6,9 @@ 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;
+  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,
+      refShortcutRegExp = /!\[([^\[\]]+)]()()()()()/g;
 
   function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
 
@@ -77,6 +78,9 @@ showdown.subParser('images', function (text, options, globals) {
   // Next, handle inline images:  ![alt text](url =<width>x<height> "optional title")
   text = text.replace(inlineRegExp, writeImageTag);
 
+  // handle reference-style shortcuts: |[img text]
+  text = text.replace(refShortcutRegExp, writeImageTag);
+
   text = globals.converter._dispatch('images.after', text, options, globals);
   return text;
 });

+ 4 - 1
test/cases/images.html

@@ -1,3 +1,6 @@
 <p><img src="/path/to/img.jpg" alt="Alt text" /></p>
 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title" /></p>
-<p><img src="url/to/image" alt="Alt text" title="Optional title attribute" /></p>
+<p><img src="url/to/image.jpg" alt="Alt text" title="Optional title attribute" /></p>
+<p><img src="url/to/image2.jpg" alt="My Image" title="Optional title attribute" /></p>
+<p>![leave me alone]</p>
+<p>![leave me alone][]</p>

+ 8 - 1
test/cases/images.md

@@ -5,4 +5,11 @@
 
 ![Alt text][id]
 
-  [id]: url/to/image  "Optional title attribute"
+![My Image]
+
+![leave me alone]
+
+![leave me alone][]
+
+  [id]: url/to/image.jpg  "Optional title attribute"
+  [My Image]: url/to/image2.jpg "Optional title attribute"

+ 1 - 0
test/cases/implicit-anchors.html

@@ -1 +1,2 @@
 <p>Search the web at <a href="http://google.com/">Google</a> or <a href="http://daringfireball.net/">Daring Fireball</a>.</p>
+<p>Search the web at <a href="http://google.com/">Google</a> or <a href="http://daringfireball.net/">Daring Fireball</a>.</p>

+ 3 - 0
test/cases/implicit-anchors.md

@@ -1,5 +1,8 @@
 
 Search the web at [Google][] or [Daring Fireball][].
 
+Search the web at [Google] or [Daring Fireball].
+
+
   [Google]: http://google.com/
   [Daring Fireball]: http://daringfireball.net/

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