Browse Source

feat(ghMentionsLink): add ability to define the generated url in @mentions

This option enables users to define the generated links in @mentions.
For instance,  with ghMentionsOption set to `//mysite.com/{u}/profile`
this text
`@tivie`
will result in this link
`<a href="//mysite.com/tivie/profile">@tivie</a>`
Estevao Soares dos Santos 8 năm trước cách đây
mục cha
commit
a4c24c9805

+ 3 - 0
README.md

@@ -294,6 +294,9 @@ var defaultOptions = showdown.getDefaultOptions();
  
  * **ghMentions**: (boolean) [default false] Enables github @mentions, which link to the username mentioned (since v1.6.0) 
  
+ * **ghMentionsLink**: (string) [default `https://github.com/{u}`] Changes the link generated by @mentions. Showdown will replace `{u}` with the username. Only applies if ghMentions option is enabled.
+   Example: `@tivie` with ghMentionsOption set to `//mysite.com/{u}/profile` will result in `<a href="//mysite.com/tivie/profile">@tivie</a>`
+ 
  * **encodeEmails**: (boolean) [default true] Enables e-mail addresses encoding through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities. (since v1.6.1)
 
    NOTE: Prior to version 1.6.1, emails would always be obfuscated through dec and hex encoding.

+ 12 - 1
dist/showdown.js

@@ -108,6 +108,11 @@ function getDefaultOpts(simple) {
       description: 'Enables github @mentions',
       type: 'boolean'
     },
+    ghMentionsLink: {
+      defaultValue: 'https://github.com/{u}',
+      description: 'Changes the link generated by @mentions. Only applies if ghMentions option is enabled.',
+      type: 'string'
+    },
     encodeEmails: {
       defaultValue: true,
       description: 'Encode e-mail addresses through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities',
@@ -1340,7 +1345,13 @@ showdown.subParser('anchors', function (text, options, globals) {
       if (escape === '\\') {
         return st + mentions;
       }
-      return st + '<a href="https://www.github.com/' + username + '">' + mentions + '</a>';
+
+      //check if options.ghMentionsLink is a string
+      if (!showdown.helper.isString(options.ghMentionsLink)) {
+        throw new Error('ghMentionsLink option must be a string');
+      }
+      var lnk = options.ghMentionsLink.replace(/\{u}/g, username);
+      return st + '<a href="' + lnk + '">' + mentions + '</a>';
     });
   }
 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/showdown.js.map


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/showdown.min.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/showdown.min.js.map


+ 5 - 0
src/options.js

@@ -106,6 +106,11 @@ function getDefaultOpts(simple) {
       description: 'Enables github @mentions',
       type: 'boolean'
     },
+    ghMentionsLink: {
+      defaultValue: 'https://github.com/{u}',
+      description: 'Changes the link generated by @mentions. Only applies if ghMentions option is enabled.',
+      type: 'string'
+    },
     encodeEmails: {
       defaultValue: true,
       description: 'Encode e-mail addresses through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities',

+ 7 - 1
src/subParsers/anchors.js

@@ -73,7 +73,13 @@ showdown.subParser('anchors', function (text, options, globals) {
       if (escape === '\\') {
         return st + mentions;
       }
-      return st + '<a href="https://www.github.com/' + username + '">' + mentions + '</a>';
+
+      //check if options.ghMentionsLink is a string
+      if (!showdown.helper.isString(options.ghMentionsLink)) {
+        throw new Error('ghMentionsLink option must be a string');
+      }
+      var lnk = options.ghMentionsLink.replace(/\{u}/g, username);
+      return st + '<a href="' + lnk + '">' + mentions + '</a>';
     });
   }
 

+ 1 - 1
test/features/ghMentions.html

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

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác