[closure-devel] Converting html files
Andrei Stebakov
lispercat at gmail.com
Thu Apr 2 17:27:08 UTC 2009
I am new to the library so I have a couple of questions to make sure I
am on the right track.
I have a task of converting html. Say I have an html page (page1.html)
it its depth of html code it has a sertain table with a <td
id='content ...>.
This <td> element holds the important data that I want to include in
another html page (page2.html) as a <div> element with the same
content slightly modified.
Along with the <td id='content ...> I need to borrow some fragments of
javascript from page1.html to page2.html.
Right now I am doing this job with cl-html-parser, but the problem
with html parser is that it can't serialize lhtml back to html, so I
was using some additional functions to cl-who to do the job. It works,
but I'd like to find a cleaner solution with one package (I hope that
closure-html is the one) that I could do parsing + serializing.
I see that to parse the page I need to use event methods like
start-element, characters and end-elemet. Theoretically by using only
those methods it's possible for me to find the <td id='content ...>
element, set a marker in my-lhtml-builder and start to collect all the
data inside the <td> elemet, modify what I need so I come up with the
html string at the end of parsing. Along with that I woud do the same
with bits of javascript.
What seems a bit awkward here is that I can't just take the whole
parse tree under the <td>, modify it, and insert it as a block to some
other html page.
To be able to do that there needs to be some event with gives the
whole pt along with it's name and attrs.
Second, I couldn't find how I can convert <p>nada</p> to its lhtml
form and back to <p>nada</p> form (I always end up with those extra
html and head blocks around it).
Please, let me know if there is a better solution to my problem and
maybe I am missing some functionality or misunderstand the philosophy
of the library.
Thank you,
Andrei
More information about the closure-devel
mailing list