<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Antanova Ltd. &#187; javascript</title>
	<atom:link href="http://antanova.com/tags/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://antanova.com</link>
	<description>We make excellent websites</description>
	<lastBuildDate>Tue, 30 Mar 2010 09:08:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Twitter status text links made clickable</title>
		<link>http://antanova.com/blog/code-bits/twitter-status-text-links-made-clickable</link>
		<comments>http://antanova.com/blog/code-bits/twitter-status-text-links-made-clickable#comments</comments>
		<pubDate>Tue, 23 Feb 2010 15:35:55 +0000</pubDate>
		<dc:creator>Jason C</dc:creator>
				<category><![CDATA[Code-bits]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://antanova.com/?p=446</guid>
		<description><![CDATA[I needed to transform plain tweets into something clickable, so I made a JavaScript function for it.]]></description>
			<content:encoded><![CDATA[<p>A new design agency being formed by an existing client needed a site. They had a good design ready, I just had to build the thing. It&#8217;s built in Wordpress, but I also pull in their Twitter stream on the client side.</p>
<p><a href="http://apiwiki.twitter.com/">Twitter&#8217;s api</a> is easy enough to use. I opted for the JSON-p format, but something I didn&#8217;t realise at the time was that the status updates are purely the plain text. So any URLs, usernames or hashtags are just plain text: no wrapping in &lt;a&gt;&lt;/a&gt; tags. It&#8217;s an easy problem to solve, though, and here it is for anyone else who needs it.</p>
<pre><code>function twitify( text )
{
    // replace urls with linked ones
    var t2 = text.replace(/(http|https)(:\/\/)([^ ]+)/ig, '&lt;a href="$1$2$3"&gt;$1$2$3&lt;/a&gt;' );

    // replace @username with clickable twitter link
    t2 = t2.replace(/@([^ ]+)/gi,'&lt;a href="http://twitter.com/$1"&gt;@$1&lt;/a&gt;');

    // replace hashtags with Twitter searches
    t2 = t2.replace(/#([^ ]+)/gi,'&lt;a href="http://search.twitter.com/search?q=%23$1"&gt;#$1&lt;/a&gt;');

    return t2;
}
</code></pre>
<p>So, feed the tweet into that function, and back out it comes with links, @users and #hastags made clickable.</p>
<p>Did I mention I ♥ regular expressions?</p>
]]></content:encoded>
			<wfw:commentRss>http://antanova.com/blog/code-bits/twitter-status-text-links-made-clickable/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
