A jQuery plugin that transforms Twitter related entities from plain text into hyperlinks.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
jquery.tweet-linkify.js
jquery.tweet-linkify.min.js

README.md

jQuery Tweet Linkify

This is a small jQuery plugin that transforms @mention texts into hyperlinks pointing to the actual Twitter profile, #hashtag texts into real hashtag searches, as well as hyperlink texts into actual hyperlinks.

The hyperlink text transforming was based off of jLinker.js by Michalis Tzikas and Vasilis Lolos.

How to use

Basic Usage

Let's say you have this tweet:

This is a test tweet to @terenceponce http://t.co/something #YOLO

<p class="tweet">This is a test tweet to @terenceponce http://t.co/something</p> #YOLO

Doing $('p.tweet').tweetLinkify(); will transform the text into this:

This is a test tweet to @terenceponce http://t.co/something #YOLO

<p class="tweet">This is a test tweet to <a href="http://twitter.com/terenceponce">@terenceponce</a> <a href="http://t.co/something">http://t.co/something</a> <a href="https://twitter.com/search/?src=hash&q=%23YOLO">#YOLO</a></p>

Advanced Usage

The plugin accepts multiple options:

  • excludeHyperlinks - Excludes hyperlink texts from being transformed. Defaults to false
  • excludeMentions - Excludes @mention texts from being transformed. Defaults to false
  • excludeHashtags - Excludes #hashtag texts from being transformed. Defaults to false
  • hyperlinkTarget - The target attribute for hyperlinks. Options are blank, self, parent, and top
  • mentionTarget - The target attribute for mentions. Options are blank, self, parent, and top
  • mentionIntent - Transforms the mention into a Twitter web user intent. Defaults to false
  • hashtagTarget - The target attribute for hashtags. Options are blank, self, parent, and top
  • hyperlinkClass - The class attribute for hyperlinks.
  • mentionClass - The class attribute for mentions.
  • hashtagClass - The class attribute for hashtags.
  • hyperlinkRel - The rel attribute for hyperlinks.
  • mentionRel - The rel attribute for mentions.
  • hashtagRel - The rel attribute for hashtags.

Let's say I want the hyperlinks and mentions to have a class name and the hyperlinks to open to a new tab instead of the same window. Using the previous example:

var options = {
  hyperlinkTarget: 'blank',
  hyperlinkClass: 'yolo',
  mentionClass: 'swag'
};

$('p.tweet').tweetLinkify(options);

Will transform into this:

<p class="tweet">This is a test tweet to <a href="http://twitter.com/terenceponce" class="swag">@terenceponce</a> <a href="http://t.co/something" target="_blank" class="yolo">http://t.co/something</a> <a href="https://twitter.com/search/?src=hash&q=%23YOLO">#YOLO</a></p>