On Jan 23, 3:33 pm, Craig in Calgary <[email protected]> wrote: > I have several scripts that generate lists of tiddlers. In order for > ordered and unordered lists to render properly there are liberal > instances of "\n". I would like to run the "return" variable through a > function to eliminate the extra vertical white space. Typically, the > end of a nested list has 2 or 3 crlfs when 1 is sufficient. A > javascript loop with a regex query to find all instances of multiple > crlfs preceding an "<li>" and replace that with a single crlf + "<li>" > would clean up my output very nicely. Can a javascript guru slap a > half-dozen lines of code together to point me in the right direction?
It will only take *one* line of code! Use the .replace() method: txt=txt.replace(/\n+<li>/g,"\n<li>"); where the first param is the regex pattern to match and the second param is the replacement text. Within the regex, "\n+" matches one or more newlines, and the trailing /.../g means "global" i.e., match (and replace) all instances. enjoy, -e Eric Shulman TiddlyTools / ELS Design Studios ---- TiddlyTools needs YOUR financial support... Help ME to continue to help YOU... make a generous donation today: http://www.TiddlyTools.com/#Donations Professional TiddlyWiki Consulting Services... Analysis, Design, and Custom Solutions: http://www.TiddlyTools.com/#Contact -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/tiddlywiki?hl=en.

