mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
Re-factored @roberocity 's twitter autolinks into extension format
This commit is contained in:
parent
4234de3a91
commit
7db254fcb2
38
src/extensions/twitter.js
Normal file
38
src/extensions/twitter.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
var twitter = function(converter) {
|
||||||
|
return [
|
||||||
|
|
||||||
|
// @username syntax
|
||||||
|
{ type: 'lang', regex: '\\B(\\\\)?@([\\S]+)\\b', replace: function(match, leadingSlash, username) {
|
||||||
|
// Check if we matched the leading \ and return nothing changed if so
|
||||||
|
if (leadingSlash === '\\') {
|
||||||
|
return match;
|
||||||
|
} else {
|
||||||
|
return '<a href="http://twitter.com/' + username + '">@' + username + '</a>';
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
|
||||||
|
// #hashtag syntax
|
||||||
|
{ type: 'lang', regex: '\\B(\\\\)?#([\\S]+)\\b', replace: function(match, leadingSlash, tag) {
|
||||||
|
// Check if we matched the leading \ and return nothing changed if so
|
||||||
|
if (leadingSlash === '\\') {
|
||||||
|
return match;
|
||||||
|
} else {
|
||||||
|
return '<a href="http://twitter.com/search/%23' + tag + '">#' + tag + '</a>';
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
|
||||||
|
// Escaped @'s
|
||||||
|
{ type: 'lang', regex: '\\\\@', replace: '@' }
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Client-side export
|
||||||
|
if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) { window.Showdown.extensions.twitter = twitter; }
|
||||||
|
// Server-side export
|
||||||
|
if (typeof module !== 'undefined') module.exports = twitter;
|
||||||
|
|
||||||
|
}());
|
Loading…
Reference in New Issue
Block a user