The CreatorCon Call for Content is officially open! Get started here.

How to extract html tags from Knowledge Articles?

Community Alums
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

Community Alums
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) ;


}


Community Alums
Not applicable

Yes. We need that


Thanks a lot Venkat.


Great. Hope the issue is completely resolved.


Community Alums
Not applicable

Yes. It is resolved. Looks great.



find_real_file.png