Skip to content
Convert a tweet into HTML, parsing out #hashtags, @mentions and http://links.com
JavaScript
Find file
Latest commit 3c14718 Mar 5, 2015 @domharrington 1.1.1
Failed to load latest commit information.
example add example Mar 19, 2013
test Initial commit Mar 19, 2013
.gitignore add example Mar 19, 2013
.jshintrc Initial commit Mar 19, 2013
.travis.yml Drop 0.8 and 0.6 support. Add support for 0.12 and iojs Mar 5, 2015
LICENSE Initial commit Mar 19, 2013
README.md Initial commit Mar 19, 2013
index.js Upgrade dependencies Mar 5, 2015
package.json 1.1.1 Mar 5, 2015

README.md

build status

html-tweet

Convert a tweet into HTML, parsing out #hashtags, @mentions and http://links.com. Uses the official twitter-text npm package for parsing.

usage

var htmlTweet = require('html-tweet')()

var html = htmlTweet('Hello #world, this is a @mention and a http://link.com')

console.log(html);
// html => "Hello <a href='#'>#world</a>, this is a <a href='#'>@mention</a> and a <a href='#'>http://link.com</a>"

methods

var htmlTweet = require('html-tweet')()

htmlTweet(tweet)

Returns a HTML version of the tweet text.

options

Options can be passed to require with template strings for the hashtags, urls and mentions. Uses lodash/underscore template strings: <a href='#'><%= hashtag %></a>.

Options are as follows:

  • hashtag - hashtag template string
    • default: <a href='#'><%= hashtag %></a>
  • mention - mention template string
    • default: <a href='#'><%= mention %></a>
  • url - url template string
    • default: <a href='#'><%= url %></a>

E.g:

var htmlTweet = require('html-tweet')(
  { hashtag: '<a class=\'hashtag\' href=\'#\'><%= hashtag %></a>'
  , mention: '<a class=\'mention\' href=\'#\'><%= mention %></a>'
  , url: '<a class=\'url\' href=\'#\'><%= url %></a>'
  })

install

npm install html-tweet
Something went wrong with that request. Please try again.