Discussion:
Parsing html and creating a new output
Andrei Stebakov
2007-11-24 22:25:50 UTC
Permalink
I am using drakma to get the html and cl-html-parse to parse it.
Let's say I need to parse and modify the html and use hunchentoot to
handle the request giving out the new html.
In cl-who I see only the macro with-html-output-to-string which prints
html given a body of s-exp.
In my case I will only have a list of s-exp like '(:div "some text").
If I give a list to with-html-output-to-string it will return an empty
string.
I am wondering is there a function inside cl-who that I can use to
convert s-exp html list like '(:body "some body") to an HTML text? Or
how can I use the with-html-output-to-string macro for the purpose?

Thank you,
Andrew
Edi Weitz
2007-11-24 23:40:07 UTC
Permalink
Post by Andrei Stebakov
I am wondering is there a function inside cl-who that I can use to
convert s-exp html list like '(:body "some body") to an HTML text?
No, unfortunately there isn't. I wanted to add that for quite some
time now, but it implies a major rewrite of CL-WHO's internals and I
don't have time for this ATM. Maybe you can use one the related tools
like htout, LML, or htmlgen for this.

Edi.
Richard Newman
2007-11-24 23:52:06 UTC
Permalink
Post by Edi Weitz
Post by Andrei Stebakov
I am wondering is there a function inside cl-who that I can use to
convert s-exp html list like '(:body "some body") to an HTML text?
No, unfortunately there isn't. I wanted to add that for quite some
time now, but it implies a major rewrite of CL-WHO's internals and I
don't have time for this ATM. Maybe you can use one the related tools
like htout, LML, or htmlgen for this.
I don't know if the innards of CL-WHO have changed in the two years
since I wrote my code, but I did put together a hack that did exactly
this, calling APPLY-TO-TREE and TREE-TO-TEMPLATE with a rewritten -
AUX function.

Rather than walking an expression inside a macro, producing code to
print HTML, we walk the form inside a function, printing strings
directly.

I don't know if it still works, but it's under 100 lines, so you
should be able to replicate it pretty easily.

-R
Edi Weitz
2007-11-25 00:00:28 UTC
Permalink
Post by Richard Newman
I don't know if the innards of CL-WHO have changed in the two years
since I wrote my code, but I did put together a hack that did
exactly this, calling APPLY-TO-TREE and TREE-TO-TEMPLATE with a
rewritten - AUX function.
Rather than walking an expression inside a macro, producing code to
print HTML, we walk the form inside a function, printing strings
directly.
I don't know if it still works, but it's under 100 lines, so you
should be able to replicate it pretty easily.
Why don't you send it to the list?
Richard Newman
2007-11-25 00:05:00 UTC
Permalink
Post by Edi Weitz
Post by Richard Newman
I don't know if it still works, but it's under 100 lines, so you
should be able to replicate it pretty easily.
Why don't you send it to the list?
Let me test if it works :)

(I'll also fight through my embarrassment over old code...)
Richard Newman
2007-11-25 00:16:49 UTC
Permalink
Here's my contribution; it still works in 0.9.1!

Please forgive any horrible hackiness you find -- this code was never
written for public consumption :)


who(11): (tree-to-string '(:body (:b "Foo bar") (:i :style "baz"
"boo")))
"<body><b>Foo bar</b><i style='baz'>boo</i></body>"
Edi Weitz
2007-11-25 00:20:26 UTC
Permalink
Post by Richard Newman
Here's my contribution; it still works in 0.9.1!
Thanks. I'll have a look at it in the next days/weeks when I find
some time.
Andrei Stebakov
2007-11-25 16:47:58 UTC
Permalink
Richard, I tried it and it works. I didn't test it for many cases only
for some simple ones that I currently use.
That would be great to integrate the functionality into cl-who.

Richard, Edi thank you for your support!

Andrew
Post by Edi Weitz
Post by Richard Newman
Here's my contribution; it still works in 0.9.1!
Thanks. I'll have a look at it in the next days/weeks when I find
some time.
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
Andrei Stebakov
2009-03-24 02:26:41 UTC
Permalink
Edi, I wonder if you plan to incorporate Richard's code into cl-who?
It's a function which returns an html string from a list of s-exp.

Thank you,
Andrei
Post by Andrei Stebakov
Richard, I tried it and it works. I didn't test it for many cases only
for some simple ones that I currently use.
That would be great to integrate the functionality into cl-who.
Richard, Edi thank you for your support!
Andrew
Post by Richard Newman
Here's my contribution; it still works in 0.9.1!
Thanks.  I'll have a look at it in the next days/weeks when I find
some time.
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
Loading...