On 30/12 01:07:26, Peter Wright wrote:
> On 29/12 00:55:50, felix winkelmann wrote:
[ snip ]
> > I have uploaded a new version of spifffy (2.39) that does it the
> > way sxml-transforms do it (thanks, Zbigniew, for the suggestion,
> > BTW). I also renamed "sxml->html" to "write-sxml" (but kept the
> > old name for backwards compatibility).
> >
> > Peter (Wright): could you try the currently available spiffy?
>
> Yep, tried it. It works fine re: the specific problem I had with the
> earlier version (thanks), but the sxml-transforms version (which I
> hadn't previously noticed) seems to work a little better... for some
> value of "better". :-)
After some more experimenting with both the sxml-transforms and spiffy
versions of sxml->html, I decided I liked the way sxml-transforms did
it, but wanted it in spiffy. :)
Hence my following attempt at a patch for the latest spiffy-base.scm
which also incorporates (steals? :)) the sxml-transforms special
handling for (a) inline tags, and (b) certain tags when they're empty.
Would you mind having a look, Felix (or whoever the spiffy maintainer
is)? It seems to work correctly, given my (fairly brief) testing,
but it may well deserve some tweakage.
Thanks,
Pete.
--
http://flooble.net/blog
The secret is in the straw. You have to take straw from at least three
different threads. That way, the strawman you end up with is confusing
to your average schmuck. -- C&J on strawmen, alt.fan.grrm
--- spiffy-base.scm 2006-12-31 23:59:52.000000000 +0800
+++ spiffy-base-new.scm 2007-01-01 00:00:23.000000000 +0800
@@ -504,21 +504,35 @@
;;; SXML stuff:
+;; These elements use the minimized close tag form; all others will
+;; have an explicit close tag.
+(define xhtml-empty-elements '(base meta link hr br param img area input col))
+;; These open tags will not have a newline prefixed, so as not to
+;; introduce extraneous whitespace.
+(define xhtml-inline-elements
+ '(a abbr acronym cite code dfn em font kbd q samp strong var
+ b big i small strike sub sup tt u blink span))
+
(define (write-sxml sxml . port)
(let ([port (:optional port (current-output-port))])
(let rec ([sxml sxml])
(match sxml
[(tag ('@ . attrs) . data)
- (fprintf port "~%<~A" tag)
+ (if (memq tag xhtml-inline-elements)
+ (fprintf port "<~A" tag)
+ (fprintf port "~%<~A" tag))
(for-each
(match-lambda
[(name val) (fprintf port " ~A=~S" name (htmlize val))]
[(name) (fprintf port " ~A=~S" name name)]
[a (error "invalid SXML attribute syntax" a)] )
attrs)
- (write-char #\> port)
- (for-each rec data)
- (fprintf port "</~A>" tag) ]
+ (if (and (null? data) (memq tag xhtml-empty-elements))
+ (fprintf port " />")
+ (begin
+ (write-char #\> port)
+ (for-each rec data)
+ (fprintf port "</~A>" tag)))]
[(tag . data) (rec `(,tag (@) . ,data))]
[_ (display (htmlize (with-output-to-string (cut display sxml))) port)] ) ) ) )
_______________________________________________
Chicken-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-users