Tell me, please, can anyone meet the code, which is a string like

(p "qqqqaaaa" (tr (td "www") (td "eee"))) 

Converts to html or xml of the form:

 < p >qqqqaaaa< tr >< td > www < /td > < td> eee< /td> < /tr> < /p> 

There will be few tags at the input, i.e. only basic formatting elements, no frills. We need the simplest parser, in php or javascript, or an algorithm.

    2 answers 2

    An example of such a function. In the data (in (td "www") this is www) you cannot use _ "_.
    I note that this is not the fastest implementation.

     function parse(str){ var re1 = /\(([\w]+) \"([^\"]+)\"\)/, re1_ = '"<$1>$2</$1>"', re2 = /\"[ ]+\"/, re2_ = ''; var tmp; while( ( tmp = str.replace( re1, re1_ ) ) != str ){ str = tmp.replace( re2, re2_ ); } return str; } str = '(p "qqqqaaaa" (tr (td "www") (td "eee")))'; parse( str ); 
    • Thanks, I already managed it myself - deivan_

    The structure of the information is a list in the scheme. Accordingly, such strings are understood by Lisp languages ​​in the forehead, and it should be easy to output them in xml-format. If another language is needed, then the task of parsing Lisp lists in this particular language was probably solved more than once.

    • Indeed, the list comes from Lisp, but the parser needs javascript or php. I am looking for specifics, I ask for help from the community, because I have not yet found it on my own. - deivan_