AnsweredAssumed Answered

Restore UL LI Custom Function - Need Some Help to Finish

Question asked by jeffmdm on Apr 23, 2016
Latest reply on Apr 23, 2016 by jeffmdm

I'm using the HTMLtoText custom function from briandunning.com to remove all of the tags from some website product descriptions.  It places carriage returns (CRs) at the end of every line so essentially it ends up with a value list of sentences.  When it removes <li></li>  tags it replaces them with hard coded bullets at the beginning of the sentence.  For my purposes I'd like to restore the <ul></ul> and <li></li> tags to the cleaned text.

 

So for example the cleaned text might look like this:

Lorem ipsum dolor sit amet

Lorem ipsum dolor sit amet

Lorem ipsum dolor sit amet

Lorem ipsum dolor sit amet

 

It's trivial to change the bullets to <li>.  The next step is to change the CR to </li> at the end of a line that begins with <li>, for which I came up with this:

 

Let ( [ Start = Position ( text ; "<li>" ; 1 ; 1 ) ; End = Position ( text ; "¶" ; Start ; 1 )] ; Replace ( text ; End ; 1 ; "</li>" ) )

 

which works fine for the first line, resulting in this:

 

<li>Lorem ipsum dolor sit amet</li><li>Lorem ipsum dolor sit amet

<li>Lorem ipsum dolor sit amet

<li>Lorem ipsum dolor sit amet


My question is how to make this operate for the remaining lines that begin with <li> ?  Note that in actual listings there are usually lines that don't begin with bullet / <li> either before, after or before and after the bulleted section.

 

I know there's a function that counts how many items are in a value list, so that could be used to generate the "n" for a loop, but I don't know how to create the loop to make this run through each line.  Maybe the right approach is a script, or a recursive function, my head is spinning from reading the manual and looking at other custom functions for something I can follow and make work.

 

Can someone lend a hand?  Many thanks!

Outcomes