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 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:
FINAL TEXT =
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;
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.
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.