Skip to content

Commit

Permalink
feat(ghMentionsLink): add ability to define the generated url in @men…
Browse files Browse the repository at this point in the history
…tions

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>`
  • Loading branch information
tivie committed Jan 28, 2017
1 parent dbf876b commit a4c24c9
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/options.js
Expand Up @@ -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',
Expand Down
8 changes: 7 additions & 1 deletion src/subParsers/anchors.js
Expand Up @@ -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>';
});
}

Expand Down
2 changes: 1 addition & 1 deletion 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>

0 comments on commit a4c24c9

Please sign in to comment.