vendredi 18 janvier 2019

Replacing all uses of @[word] to link to twitter account in String

I'm trying to replace all uses of @[Insert_handle_here] to a link to the respective twitter account.

This is my current code.

function replaceAts(){
    for (var i=0; i<list.length;i++){
        list[i].text=list[i].text.replace(/@(\w+)/g, '<a href="https://twitter.com/$1" target="_blank">%$1</a>')
    }
}

I'm not really sure how it works, as I pretty much directly coped from another Stack Overflow post, but its showing up really weird on the actual web page.

For example, the text from my friends account

If you want these foams Ima give you the chrome @WillThaRapper

Shows up as If you want these foams Ima give you the chrome &lt;a href&#x3D;&quot;https:&#x2F;&#x2F;twitter.com&#x2F;WillThaRapper&quot; target&#x3D;&quot;_blank&quot;&gt;%WillThaRapper&lt;&#x2F;a&gt;

Which is not ideal.

Any advice?




Aucun commentaire:

Enregistrer un commentaire