Html formatting of Tweet Text


I receive the tweets of a user using the REST API. I would like to show the tweets of the user on my website. Is there a good “html formatter” like Autolinker to create proper html for all mentions, handles and links.


I’m not aware of anything that does that specifically, but if you use the oEmbed endpoint you can get embeddable Tweets and timelines with proper Twitter formatting directly. The twitter-text component can also help you to perform tokenization of the Tweet text content, but it does not also provide HTML output.


Thanks Andy for replying.
As far as my understanding goes the oEmbed endpoint would actually go to twitter and get the whole tweet with html. I dont want that to happen. I am downloading the tweet using REST API, translating it and then showing to the user. If I used oEmbed this would not be possible, right ?

Also I did find that twitter-text does give me html output. here is a sample

var twttr = require( ‘twitter-text’ );
var textToAutolink = ‘#destacada Una víctima, a Rajoy: “¿Cuántos actos se han hecho por las víctimas de Hipercor?”’;
var formattedText = twttr.autoLink(textToAutolink);


#destacada Una víctima, a Rajoy: “¿Cuántos actos se han hecho por las víctimas de Hipercor?”

There is another npm package I found that is helpful - Autolinker.


Right, your understanding of the oEmbed API is correct there.

Ah - I’d forgotten that twitter-text could do that, then! I’ve used it for tokenising and checking the validity of Tweet text rather than doing the linking. That code is maintained by our teams, so it is probably your best bet in that case.