Convert HTML into text with code

Hello everybody,

I have some collections to display sport athletics chronicles, the field for the chronique is an RICH HTML type.

If I show the field content when the text field is connected to the collection the HTML is shown correct. But in a page, I want to show only the first words of the chronicle with “…continue reading”, so I use this code:

let fullText;
let shortText;

$w.onReady( function () {
$w(“#repeater1”).onItemReady( ($w, itemData, index) => {
const shortTextLength = 200;
const monthNames = [“Gener”, “Febrer”, “Març”, “Abril”, “Maig”, “Juny”, “Juliol”, “Augost”, “Setembre”, “Octubre”, “Novembre”, “Desembre”];

const strDate =;
const strMonth = monthNames[];
const strYear =;

    $w("#text20").text = strDate + " de " + strMonth + " de " + strYear; 
    fullText = itemData.cronica; 
    shortText = fullText.substr(0, shortTextLength) + " (continuar llegint...)."; 

    $w("#text22").text = shortText; 


Here I convert the DATE & TIME format into my language avoiding to show the hour and i works.

But when I want to show the first 200 chars of the field Data.cronica, the variable shortText gets the HTML format and it don’t show the text. Take a look:

Under Tipus: 5 km you can see the text with all the HTML tags.

How could I convert the rich HTML into plain text without the tags?

And another question. I’d like that the text “…continue reading” would be a link to the full chronicle. How could do it?

Thanks a lot,
Francesc Gallardo


did you manage to fix the issue? i could not see what you described in your web site.
for security reasons it is not recommended to copy full html sections from an untrusted source, so the best option is to strip the data before it you insert it to your collection. there are online tools that can help you with that. in addition you will have to do the striping before displaying the data anywhere in your website

regarding the other question you had, please have a look here:


Have you tried

$w(" #text22 ").html = shortText;

as explained here: Text - Velo API Reference - ?