Forráskód Böngészése

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

Closes #51
Estevao Soares dos Santos 8 éve
szülő
commit
f2671c0cc7

+ 0 - 5
CHANGELOG.md

@@ -1,11 +1,6 @@
 <a name="1.5.5"></a>
 ## [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
 
 * **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)
  
+ * **ghMentions**: (boolean) [default false] Enables github @mentions, which link to the username mentioned (since v1.5.6) 
+ 
 ## 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,
       description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)',
       type: 'boolean'
+    },
+    ghMentions: {
+      defaultValue: false,
+      description: 'Enables github @mentions',
+      type: 'boolean'
     }
   };
   if (simple === false) {
@@ -152,7 +157,8 @@ var showdown = {},
         disableForced4SpacesIndentedSublists: true,
         simpleLineBreaks:                     true,
         requireSpaceBeforeHeadingText:        true,
-        ghCompatibleHeaderId:                 true
+        ghCompatibleHeaderId:                 true,
+        ghMentions:                           true
       },
       vanilla: getDefaultOpts(true),
       allOn: allOptionsOn()
@@ -1206,11 +1212,16 @@ showdown.subParser('anchors', function (text, options, globals) {
   text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,
                       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]
   // or [link test](/foo)
   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);
   return text;
 });
@@ -1601,6 +1612,7 @@ showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text) {
   return text;
 });
 
+
 /**
  * Handle github codeblocks prior to running HashHTML so that
  * HTML contained within the codeblock gets escaped properly

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/showdown.js.map


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/showdown.min.js


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/showdown.min.js.map


+ 5 - 0
src/options.js

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

+ 2 - 1
src/showdown.js

@@ -22,7 +22,8 @@ var showdown = {},
         disableForced4SpacesIndentedSublists: true,
         simpleLineBreaks:                     true,
         requireSpaceBeforeHeadingText:        true,
-        ghCompatibleHeaderId:                 true
+        ghCompatibleHeaderId:                 true,
+        ghMentions:                           true
       },
       vanilla: getDefaultOpts(true),
       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,
                       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]
   // or [link test](/foo)
   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);
   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});
     } else if (testsuite[i].name === '#320.github-compatible-generated-header-id') {
       converter = new showdown.Converter({ghCompatibleHeaderId: true});
+    } else if (testsuite[i].name === 'ghMentions') {
+      converter = new showdown.Converter({ghMentions: true});
     } else {
       converter = new showdown.Converter();
     }

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott