0

I am working on the project and I have a problem. The thing is I need to decode html that I get as a part of JSON object from API. The html is quite tricky so I need to ask for your help guys.

That is the sample value that I need to translate into plain text:

<div class=text-primary>\rSave up to 49% bla bla some text, text, text World of text and text text. For text details of text prices, click on the location required.<br>\r <table width=100%><tr><td width=10%></td><td width=80%><div class="well text-center"><h5><b>To text your text text call</b><h5><h5><b>0871 222 text and quote</b></h5><h4><b>ELG2017</b></h4></div></td><td width=10%></td></tr></table>\r

Yeah I know, it's horrible. Well, that's what I have to decode..

Thanks a lot!

2
  • What do you mean by decode? Parse it for values? Display as HTML? Commented Jul 4, 2017 at 9:33
  • Turn this horrible bit of code into plain text. Ideally preserving line breaks. Commented Jul 4, 2017 at 9:59

3 Answers 3

2

text.replace(/<[^>]*>/g, '');

Sign up to request clarification or add additional context in comments.

Comments

0

You can use something like this:

htmlToText(html) {
  var tmp = document.createElement('DIV'); // TODO: Check if this the way to go with Angular
  tmp.innerHTML = html;
  return tmp.textContent || tmp.innerText || '';
}

https://jsfiddle.net/z762py3s/

Comments

0
text.replace(new RegExp("\\\\n", "g"), ", ")

and use [innerHTML] for view

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.