فهرست منبع

Re-factored @roberocity 's twitter autolinks into extension format

Titus 13 سال پیش
والد
کامیت
7db254fcb2
1فایلهای تغییر یافته به همراه38 افزوده شده و 0 حذف شده
  1. 38 0
      src/extensions/twitter.js

+ 38 - 0
src/extensions/twitter.js

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