Html to text

Hello everyone,
I have content in my products in html format:

Date of publication : & nbsp; 08.10.2020

I would like to convert this content to plain text without html tags to get:
“Publication date: 08.10.2020”
I tried with replace () but it only partially works
var strippedHtml = myHTML.replace (/ <[^>] +> / g, ‘’);
console.log (“New string =” + strippedHtml);

First of all, there’s a mistake in your original html string (an extra space between the & and the nsbp;).
But let’s say you use an html string without mistakes, then you can do:

 var strippedHtml = myHTML.replace(/<[^>]*>?/g, '');

I think the easiest way will be to use an NPM for that.
For example:
Go to the NMPs, search for the he package and install it.
Then on the webpage:

const he = require('he');
const finalText = he.decode(strippedHtml);

There’re other packages as well

Thanks for this answer but I don’t know what NMPs is or where to find the package you are talking about !?

Thanks, it actually works.

Thank you very much, I did not know this code library at all. Really very helpful.
I learn about it every day.
Thanks for your help.

I have tried the suggested solution but I do not get the desired result.
I have an " infodetail " variable which contains the string:

Date of publication : & nbsp; 08/10/2020 & nbsp; Number of pages : & nbsp; 366

I tried the following code: as shown

const he = require (‘he’);
const finaltext = he.decode (infodetail);
console.log (“FINAL TEXT =”, finaltext);
and the “Console.log” returns me the same string:


Date of publication : 08/10/2020 Number of pages : 366 </ p>

What I want is to obtain

Publication date: 08/10/2020 Number of pages: 366

There is obviously something that I did not understand.
Thanks for your help

Finally I found a temporary solution while waiting for your lighting:

// HTML cleanup
const he = require (‘he’);
$ w (‘# detail’). text = infodetail.replace (/ <[^>] +> / g, ‘’);
const finaltext = he.decode ($ w (‘# detail’). text, ‘& nbsp;’);
$ w (‘# detail’). text = finaltext;
And i got the string :

Date de parution : 08/10/2020 Nombre de pages : 366

You have to strip the html tags first with the regex, then use the he package to decode the html string (to replace   and other code).
By the way, you still have an extra space: & nbsp;

he.decode($w(‘# detail’). text);
he.decode($w(‘# detail’). text, ‘& nbsp;’);

Hello, I follow your recommendations with the utmost care, but I again encounter an error:

When I test this code:

const he = require ( ‘he’ );
const finaltext = he . decode ( $w ( ‘#detail’ ));
$w ( ‘#detail’ ). text = finaltext ;
console . log ( finaltext );

I am getting an error ?:
Erreur TypeError: html.replace is not a function

I have no line of code with the word “replace”

You forgot the property (in red):

const finaltext=he.decode($w('#detail').text);


  1. I don’t know why you’re passing it back and forth via the text element.
  2. But if you o pass it via an element you don’t need to use regex to remove the tag nor the he library to decode the html. All you need is:
$w('#text1').html = originalHtmlString;
$w('#text1').html = `<p>${$w('#text1').text}</p>`;

With your indications my code works. So a big thank you.
I have to go through a variable of type text.
Otherwise the “product description” field of wix-store returns me a text in bold characters and which does not take into account the fonts used in the theme of the site. This is the reason why I prefer to recover plain text.

In the “Products” collection of wix-store, the product description field is “rich text” but I haven’t found a way to get its content as it is.

I am attaching an image, hoping it will be clearer.

What if you just use a single line:

$w('#text1').html = originalHtmlString;

And that’s all. Will it work okay for you?

In absolute terms it works, I recover the HTML content well but the characters are bold like the previous result. Even if I put the field in 8 pixels font for example, I still get the same result. The display does not take into account the text themes of the site.