Răsfoiți Sursa

feat(ghMentions): add support for github's @mentions

Closes #51
Estevao Soares dos Santos 8 ani în urmă
părinte
comite
f2671c0cc7

+ 0 - 5
CHANGELOG.md

@@ -1,11 +1,6 @@
 <a name="1.5.5"></a>
 <a name="1.5.5"></a>
 ## [1.5.5](https://github.com/showdownjs/showdown/compare/1.5.4...1.5.5) (2016-12-30)
 ## [1.5.5](https://github.com/showdownjs/showdown/compare/1.5.4...1.5.5) (2016-12-30)
 
 
-
-### Bug Fixes
-
-* **ghCompatibleHeaderId:** add % as an escaped char ([3102615](https://github.com/showdownjs/showdown/commit/3102615))
-
 ### Features
 ### Features
 
 
 * **ghCompatibleHeaderId:** generate header ids compatible with github ([db97a90](https://github.com/showdownjs/showdown/commit/db97a90)), closes [#320](https://github.com/showdownjs/showdown/issues/320) [#321](https://github.com/showdownjs/showdown/issues/321)
 * **ghCompatibleHeaderId:** generate header ids compatible with github ([db97a90](https://github.com/showdownjs/showdown/commit/db97a90)), closes [#320](https://github.com/showdownjs/showdown/issues/320) [#321](https://github.com/showdownjs/showdown/issues/321)

+ 2 - 0
README.md

@@ -292,6 +292,8 @@ var defaultOptions = showdown.getDefaultOptions();
 
 
  * **requireSpaceBeforeHeadingText**: (boolean) [default false] Makes adding a space between `#` and the header text mandatory (since v1.5.3)
  * **requireSpaceBeforeHeadingText**: (boolean) [default false] Makes adding a space between `#` and the header text mandatory (since v1.5.3)
  
  
+ * **ghMentions**: (boolean) [default false] Enables github @mentions, which link to the username mentioned (since v1.5.6) 
+ 
 ## Flavors
 ## Flavors
 
 
 You can also use flavors or presets to set the correct options automatically, so that showdown behaves like popular markdown flavors.
 You can also use flavors or presets to set the correct options automatically, so that showdown behaves like popular markdown flavors.

+ 14 - 2
dist/showdown.js

@@ -102,6 +102,11 @@ function getDefaultOpts(simple) {
       defaultValue: false,
       defaultValue: false,
       description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)',
       description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)',
       type: 'boolean'
       type: 'boolean'
+    },
+    ghMentions: {
+      defaultValue: false,
+      description: 'Enables github @mentions',
+      type: 'boolean'
     }
     }
   };
   };
   if (simple === false) {
   if (simple === false) {
@@ -152,7 +157,8 @@ var showdown = {},
         disableForced4SpacesIndentedSublists: true,
         disableForced4SpacesIndentedSublists: true,
         simpleLineBreaks:                     true,
         simpleLineBreaks:                     true,
         requireSpaceBeforeHeadingText:        true,
         requireSpaceBeforeHeadingText:        true,
-        ghCompatibleHeaderId:                 true
+        ghCompatibleHeaderId:                 true,
+        ghMentions:                           true
       },
       },
       vanilla: getDefaultOpts(true),
       vanilla: getDefaultOpts(true),
       allOn: allOptionsOn()
       allOn: allOptionsOn()
@@ -1206,11 +1212,16 @@ showdown.subParser('anchors', function (text, options, globals) {
   text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,
   text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,
                       writeAnchorTag);
                       writeAnchorTag);
 
 
-  // Last, handle reference-style shortcuts: [link text]
+  // handle reference-style shortcuts: [link text]
   // These must come last in case you've also got [link test][1]
   // These must come last in case you've also got [link test][1]
   // or [link test](/foo)
   // or [link test](/foo)
   text = text.replace(/(\[([^\[\]]+)])()()()()()/g, writeAnchorTag);
   text = text.replace(/(\[([^\[\]]+)])()()()()()/g, writeAnchorTag);
 
 
+  // Lastly handle GithubMentions if option is enabled
+  if (options.ghMentions) {
+    text = text.replace(/(^|\s)(@([a-z\d\-]+))(?=[.!?;,[\]()]|\s|$)/gmi, '$1<a href="https://www.github.com/$3">$2</a>');
+  }
+
   text = globals.converter._dispatch('anchors.after', text, options, globals);
   text = globals.converter._dispatch('anchors.after', text, options, globals);
   return text;
   return text;
 });
 });
@@ -1601,6 +1612,7 @@ showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text) {
   return text;
   return text;
 });
 });
 
 
+
 /**
 /**
  * Handle github codeblocks prior to running HashHTML so that
  * Handle github codeblocks prior to running HashHTML so that
  * HTML contained within the codeblock gets escaped properly
  * HTML contained within the codeblock gets escaped properly

Fișier diff suprimat deoarece este prea mare
+ 0 - 0
dist/showdown.js.map


Fișier diff suprimat deoarece este prea mare
+ 0 - 0
dist/showdown.min.js


Fișier diff suprimat deoarece este prea mare
+ 0 - 0
dist/showdown.min.js.map


+ 5 - 0
src/options.js

@@ -100,6 +100,11 @@ function getDefaultOpts(simple) {
       defaultValue: false,
       defaultValue: false,
       description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)',
       description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)',
       type: 'boolean'
       type: 'boolean'
+    },
+    ghMentions: {
+      defaultValue: false,
+      description: 'Enables github @mentions',
+      type: 'boolean'
     }
     }
   };
   };
   if (simple === false) {
   if (simple === false) {

+ 2 - 1
src/showdown.js

@@ -22,7 +22,8 @@ var showdown = {},
         disableForced4SpacesIndentedSublists: true,
         disableForced4SpacesIndentedSublists: true,
         simpleLineBreaks:                     true,
         simpleLineBreaks:                     true,
         requireSpaceBeforeHeadingText:        true,
         requireSpaceBeforeHeadingText:        true,
-        ghCompatibleHeaderId:                 true
+        ghCompatibleHeaderId:                 true,
+        ghMentions:                           true
       },
       },
       vanilla: getDefaultOpts(true),
       vanilla: getDefaultOpts(true),
       allOn: allOptionsOn()
       allOn: allOptionsOn()

+ 6 - 1
src/subParsers/anchors.js

@@ -59,11 +59,16 @@ showdown.subParser('anchors', function (text, options, globals) {
   text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,
   text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,
                       writeAnchorTag);
                       writeAnchorTag);
 
 
-  // Last, handle reference-style shortcuts: [link text]
+  // handle reference-style shortcuts: [link text]
   // These must come last in case you've also got [link test][1]
   // These must come last in case you've also got [link test][1]
   // or [link test](/foo)
   // or [link test](/foo)
   text = text.replace(/(\[([^\[\]]+)])()()()()()/g, writeAnchorTag);
   text = text.replace(/(\[([^\[\]]+)])()()()()()/g, writeAnchorTag);
 
 
+  // Lastly handle GithubMentions if option is enabled
+  if (options.ghMentions) {
+    text = text.replace(/(^|\s)(@([a-z\d\-]+))(?=[.!?;,[\]()]|\s|$)/gmi, '$1<a href="https://www.github.com/$3">$2</a>');
+  }
+
   text = globals.converter._dispatch('anchors.after', text, options, globals);
   text = globals.converter._dispatch('anchors.after', text, options, globals);
   return text;
   return text;
 });
 });

+ 0 - 0
src/subParsers/ghMentions.js


+ 2 - 0
test/features/ghMentions.html

@@ -0,0 +1,2 @@
+<p>hello <a href="https://www.github.com/tivie">@tivie</a> how are you?</p>
+<p>this email foo@gmail.com is not parsed</p>

+ 3 - 0
test/features/ghMentions.md

@@ -0,0 +1,3 @@
+hello @tivie how are you?
+
+this email foo@gmail.com is not parsed

+ 2 - 0
test/node/testsuite.features.js

@@ -51,6 +51,8 @@ describe('makeHtml() features testsuite', function () {
       converter = new showdown.Converter({requireSpaceBeforeHeadingText: true});
       converter = new showdown.Converter({requireSpaceBeforeHeadingText: true});
     } else if (testsuite[i].name === '#320.github-compatible-generated-header-id') {
     } else if (testsuite[i].name === '#320.github-compatible-generated-header-id') {
       converter = new showdown.Converter({ghCompatibleHeaderId: true});
       converter = new showdown.Converter({ghCompatibleHeaderId: true});
+    } else if (testsuite[i].name === 'ghMentions') {
+      converter = new showdown.Converter({ghMentions: true});
     } else {
     } else {
       converter = new showdown.Converter();
       converter = new showdown.Converter();
     }
     }

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff