Hi
I am trying to write "Λ" on a sink.
(let ((sink (cxml:make-character-stream-sink *standard-output* :indentation 2 :canonical nil))) (sax:start-document sink) (xhtml-generator:write-doctype sink) (xhtml-generator:with-html sink (:html (:head (:title "Titel")) (:body ((:p "style" "font-weight: bold") "Inhalt") (:ul (:li "Eins") (:li "Zwei") (:li "Λ") (:li "Drei"))))) (sax:end-document sink)) <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> Titel</title> </head> <body> <p style="font-weight: bold"> Inhalt</p> <ul> <li> Eins</li> <li> Zwei</li> <li> &Lambda;</li> <li> Drei</li> </ul> </body> </html> #<EDITOR::RUBBER-STREAM #<EDITOR:BUFFER CAPI interactive-pane 2> 219C7A3F>
How do I get it "right"?
Thank
-- Marco Antoniotti
Hi,
Quoting Marco Antoniotti (marcoxa@cs.nyu.edu):
I am trying to write "Λ" on a sink.
I don't think either the serializer nor xhtml-generator have special features to support writing entity references.
But you can write this: (sax:unescaped sink "Λ")) which will do what you are asking for (but means that you need to take care that the string is actually well-formed; cxml will not do any escaping or checking itself).
So is there a reason for the lack of entity reference writing support? Mainly just that I've never needed it myself. Usually I would just write the actual character. Λ means the same thing as the character with the code 923 on any Lisp with Unicode support, and every XML parser can Unicode characters.
In contrast, parsers need to have the DTD available to be able to read such an entity reference, and I think that the XML world in general is moving away from DTD use; it's usually more hassle than it's worth to ensure that an XML parser has the DTD available.
d.
On Wed, May 11, 2011 at 02:22:15PM +0200, David Lichteblau wrote:
So is there a reason for the lack of entity reference writing support? Mainly just that I've never needed it myself. Usually I would just write the actual character. Λ means the same thing as the character with the code 923 on any Lisp with Unicode support, and every XML parser can Unicode characters.
The entity 'λ' could mean _anything_ depending on context:
<?xml version='1.0' />
<!doctype marketing-blah [ <!ENTITY lambda "Lambda Inc. - World leader in artificial inteligence"> ]>
<marketing-bal> <title>Wlecome to the world of λ</title>
....
Bundle this with xinclude and you get a lot of reasons to support entity reference writing.
Cheers, Ralf Mattes
Ok. So this boils down to "let's get CXML" handle entities.
How do we do that?
In general I have found most (X)HTML writing facilities lacking in this or that respect. Since I am using CXM to do the reading, it would be natural not to depend on YAL (Yet Another Library) to do the reading. I am willing to help extending it, instead of rolling out my XHTMΛ (pun intended :) ) html writing facility.
One note. Having to write (cxml:unescaped sink "Λ") is a workaround, but it is not really a nice thing, since I have to manually break the string. Especially when we think of the standard SLDJ lover who tries out CXML :)
So. Somewhere, a string in a XHTML processor is "compiled" to generate SAX events. That is where the entity processing should go. Where exactly is this bit?
Cheers -- Marco
On May 11, 2011, at 15:20 , rm@tuxteam.de wrote:
On Wed, May 11, 2011 at 02:22:15PM +0200, David Lichteblau wrote:
So is there a reason for the lack of entity reference writing support? Mainly just that I've never needed it myself. Usually I would just write the actual character. Λ means the same thing as the character with the code 923 on any Lisp with Unicode support, and every XML parser can Unicode characters.
The entity 'λ' could mean _anything_ depending on context:
<?xml version='1.0' />
<!doctype marketing-blah [ <!ENTITY lambda "Lambda Inc. - World leader in artificial inteligence">
]>
<marketing-bal> <title>Wlecome to the world of λ</title>
....
Bundle this with xinclude and you get a lot of reasons to support entity reference writing.
Cheers, Ralf Mattes
-- Marco Antoniotti
Guys! Throw me a bone here!!!!!
I don't want to roll out my own XHTML generator!
So, the culprit is SAX:CHARACTERS CXML::SINK , which calls CXML::UNPARSE-INDENTED-TEXT, which calls CXML::SINK-WRITE-EXCAPABLE-ROD. This last function seems wrong as it hardcodes behavior. The problem is that nowhere in the chain there is an obvious place where to put entity handling. Or should CXML::SINK-WRITE-EXCAPABLE-ROD be rewritten? If that is the case, where should entities be found? In the sink, in a stash somewhere else? Or maybe TRT is to build a special XHTML sink?
Any ideas?
Cheers -- Marco
On May 16, 2011, at 10:58 , Marco Antoniotti wrote:
On May 16, 2011, at 09:39 , Marco Antoniotti wrote:
... Since I am using CXM to do the reading, it would be natural not to depend on YAL (Yet Another Library) to do the reading.
I meant "writing" :}
-- Marco Antoniotti
-- Marco Antoniotti
Quoting Marco Antoniotti (marcoxa@cs.nyu.edu):
Guys! Throw me a bone here!!!!!
I don't want to roll out my own XHTML generator!
So, the culprit is SAX:CHARACTERS CXML::SINK , which calls CXML::UNPARSE-INDENTED-TEXT, which calls CXML::SINK-WRITE-EXCAPABLE-ROD. This last function seems wrong as it hardcodes behavior. The problem is that nowhere in the chain there is an obvious place where to put entity handling. Or should CXML::SINK-WRITE-EXCAPABLE-ROD be rewritten? If that is the case, where should entities be found? In the sink, in a stash somewhere else? Or maybe TRT is to build a special XHTML sink?
Any ideas?
[...]
On May 16, 2011, at 10:58 , Marco Antoniotti wrote:
On May 16, 2011, at 09:39 , Marco Antoniotti wrote:
... Since I am using CXM to do the reading, it would be natural not to depend on YAL (Yet Another Library) to do the reading.
I meant "writing" :}
cxml:unescaped is the "official" solution to implement this. Please use that.
As for xhtmlgen, which you seem to be depending on: That's not an official cxml api. It is sample code based on htmlgen by Franz. I've never been a fan of htmlgen, but others like it, and I developed xhtmlgen for bknr, which needed it.
It's basically still sample code. Copy&paste material.
If you like it, just put it into your own project, and hack it as desired to add any features you want changed.
Don't try to dig into any internals within cxml's package. Just look at xhtmlgen, if that is what you want to use.
d.
On May 27, 2011, at 18:43 , David Lichteblau wrote:
Quoting Marco Antoniotti (marcoxa@cs.nyu.edu):
Guys! Throw me a bone here!!!!!
I don't want to roll out my own XHTML generator!
So, the culprit is SAX:CHARACTERS CXML::SINK , which calls CXML::UNPARSE-INDENTED-TEXT, which calls CXML::SINK-WRITE-EXCAPABLE-ROD. This last function seems wrong as it hardcodes behavior. The problem is that nowhere in the chain there is an obvious place where to put entity handling. Or should CXML::SINK-WRITE-EXCAPABLE-ROD be rewritten? If that is the case, where should entities be found? In the sink, in a stash somewhere else? Or maybe TRT is to build a special XHTML sink?
Any ideas?
[...]
On May 16, 2011, at 10:58 , Marco Antoniotti wrote:
On May 16, 2011, at 09:39 , Marco Antoniotti wrote:
... Since I am using CXM to do the reading, it would be natural not to depend on YAL (Yet Another Library) to do the reading.
I meant "writing" :}
cxml:unescaped is the "official" solution to implement this. Please use that.
That is not a solution. I do not want to write (:p "And now" (cxml:unescaped "Λ") "!") (which, besides, does not work).
As for xhtmlgen, which you seem to be depending on: That's not an official cxml api. It is sample code based on htmlgen by Franz. I've never been a fan of htmlgen, but others like it, and I developed xhtmlgen for bknr, which needed it.
It's basically still sample code. Copy&paste material.
If you like it, just put it into your own project, and hack it as desired to add any features you want changed.
Don't try to dig into any internals within cxml's package. Just look at xhtmlgen, if that is what you want to use.
Well, I wouldn't want to do anything with the internals of *any* package :)
The problem is that even looking ad XHTML-GENERATOR there are several problems in figuring out how to rewrite it using the SAX handlers. It appears to me that the only way of doing this properly is to subclass the sink class by introducing a XHTML-SINK as a hook for specialized SAX methods. Would this be the way to go?
Cheers
-- Marco Antoniotti
Quoting Marco Antoniotti (marcoxa@cs.nyu.edu):
On May 27, 2011, at 18:43 , David Lichteblau wrote:
cxml:unescaped is the "official" solution to implement this. Please use that.
That is not a solution. I do not want to write (:p "And now" (cxml:unescaped "Λ") "!") (which, besides, does not work).
OK; at this level it's called sax:unescaped, not cxml:unescaped. (In my defence, I got this right in the previous email in this thread, where I also gave the full argument list, indicating that it takes two arguments, the sink and the string.)
I can only repeat that xhtml-generator is sample-code quality, and I don't really support it. But it's very easy to hack on and extend, and that's what you can do if you are willing to dive into it:
(in-package :xhtml-generator)
(def-special-html :entity (lambda (ent args argsp body) `(sax:unescaped *html-sink* (format nil "&~(~A~);" ',(car body)))))
CL-USER> (let ((s (cxml:make-string-sink))) (sax:end-document (xhtml-generator:with-html s (:html (:body "foo" (:entity :foo) "bar")) s))) "<html><body>foo&foo;bar</body></html>"
I think that you might need to generate the sax:unescaped event, rather than the sax:escaped event that is being generated there. How you do that with xhtml-generator:with-html, I am not sure, but perhaps you could get away with:
(cxml:unescaped "λ") or failing that perhaps (progn (cxml:unescaped "λ") nil)
Hope this helps, Russ Acceleration.net
On 5/10/2011 2:18 PM, Marco Antoniotti wrote:
Hi
I am trying to write "Λ" on a sink.
(let ((sink (cxml:make-character-stream-sink *standard-output* :indentation 2 :canonical nil))) (sax:start-document sink) (xhtml-generator:write-doctype sink) (xhtml-generator:with-html sink (:html (:head (:title "Titel")) (:body ((:p "style" "font-weight: bold") "Inhalt") (:ul (:li "Eins") (:li "Zwei") (:li "Λ") (:li "Drei"))))) (sax:end-document sink))
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html> <head> <title> Titel</title> </head> <body> <p style="font-weight: bold"> Inhalt</p> <ul> <li> Eins</li> <li> Zwei</li> <li> &Lambda;</li> <li> Drei</li> </ul> </body> </html> #<EDITOR::RUBBER-STREAM #<EDITOR:BUFFER CAPI interactive-pane 2> 219C7A3F>
How do I get it "right"?
Thank
-- Marco Antoniotti