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>`
This commit is contained in:
Estevao Soares dos Santos 2017-01-28 04:28:50 +00:00
parent dbf876b6cb
commit a4c24c9805
8 changed files with 32 additions and 6 deletions

View File

@ -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.

13
dist/showdown.js vendored
View File

@ -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>';
});
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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',

View File

@ -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>';
});
}

View File

@ -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>