Sunday 15 July 2012

string - How to convert html correctly in javascript? -



string - How to convert html correctly in javascript? -

i need convert snippets of text contain html tags plain text using javascript / node.js.

i utilize string.js library that, problem when removes tags (using strip_tags() functions), removes new line.

e.g.

<div>some text</div><div>another text</div>

becomes

textanother text

do know how rid of problem? maybe library?

thanks!

try using cheerio. expose jquery interface on server side. it's just:

var html = $(htmlstring).html();

then traverse dom whatever elements want , phone call $(element).text();

javascript string node.js parsing underscore.string.js

No comments:

Post a Comment