Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to extract html tags from Knowledge Articles?

Not applicable

For CMS, trying to display all knowledge articles in a single page. So, creating a new page from scratch using jelly. I want to display two lines of the articles text for each knowledge article. How to extract the text only from the html text field? where can I find the script?

Right now it is like this,

find_real_file.png

1 ACCEPTED SOLUTION

Hi Rajini,



htmlText.stripScripts().stripTags();   is not working on <hr/> and <br/> but working on <hr> so I guess yes. let us use the regular expression as well. it will work.



function removeHTMLTagsCMS(inputId, divId){


      var htmlText = $(inputId).getValue();


      htmlText =   htmlText.stripScripts().stripTags();   // prototype methods to strip tags and strip scripts
      htmlText=htmlText.replace(/<(?:.|\s)*?>/g, " ");


      $(divId).update(htmlText) ;


}


View solution in original post

36 REPLIES 36

Not applicable

If I do that, some articles are good. But, some articles are displayed with <hr> and <br>. See below.



find_real_file.png


Hi Rajini,



htmlText.stripScripts().stripTags();   is not working on <hr/> and <br/> but working on <hr> so I guess yes. let us use the regular expression as well. it will work.



function removeHTMLTagsCMS(inputId, divId){


      var htmlText = $(inputId).getValue();


      htmlText =   htmlText.stripScripts().stripTags();   // prototype methods to strip tags and strip scripts
      htmlText=htmlText.replace(/<(?:.|\s)*?>/g, " ");


      $(divId).update(htmlText) ;


}


Not applicable

Yes. We need that


Thanks a lot Venkat.


Great. Hope the issue is completely resolved.


Not applicable

Yes. It is resolved. Looks great.



find_real_file.png