Parse Twitter Usernames, Hashtags and URLs Using jQuery

File Size: 19.4 KB
Views Total: 2754
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Parse Twitter Usernames, Hashtags and URLs Using jQuery

tweetParser is a minimal jQuery plugin that automatically parses @usernames, #hashtags and URLs within your text and turns them into Twitter links by using regular expressions.

See also:

How to use it:

1. Load jQuery library and the jQuery tweetParser plugin at the bottom of your document.

<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="jquery.tweetParser.min.js"></script>

2. Call the plugin on the text container where you wish to parse the Twitter text.

$(".tweet").tweetParser();

3. Customize the styles of your Twitter links.

.tweet {
  ...
}

.tweet_link {
  ...
}

.tweet_user {
  ...
}

4. A basic parameter to specify where to open the Twitter links.

$(".tweet").tweetParser({
target : "_blank"
});

5. All the parameters.

// css Class used for url in the tweet
"urlClass": "tweet_link",

// css Class used for @user profil url in the tweet
"userClass": "tweet_user",

// css Class used for hashtags url in the tweet
"hashtagClass": "hashtag",

// target used for all generated
"target": "_blank",

// generate hashtag link, 
// if true : "twitter.com/hashtag/", 
// if false : "twitter.com/search?q="
"searchWithHashtags": true,

// will parse @users if is set to true
"parseUsers" : true,

// will parse URLS if is set to true
"parseHashtags" : true,

// will parse hashtags if is set to true
"parseUrls" : true

Change logs:

2015-06-07

  • Improved demo.

2015-05-13

  • Improved URL parsing

2015-04-19

  • Better URL regex

2015-04-02

  • add parameter parseUsers, parseHashtags, parseUrls

2015-02-27

  • update hashtag regex

This awesome jQuery plugin is developed by VincentLoy. For more Advanced Usages, please check the demo page or visit the official website.