Re: pretty printer and PCDATA (summary)

Subject: Re: pretty printer and PCDATA (summary)
From: Brandon Ibach <bibach@xxxxxxxxxxxxxx>
Date: Thu, 9 Sep 1999 02:33:18 -0500
Quoting Frank A. Christoph <christo@xxxxxxxxxxxxxxxxxx>:
> > > In DSSSL you would use process-children-trim in place of
> > > process-children when processing the parent of nmlist.
> >
> > Yes, but I don't process it using the recursive way (process-children),
> > but by climbing back the tree.
> > BTW, how would the process-children-trim react on the end of line
> > characters ?
> I'm not sure what "climbing back the tree" means, but the other way to do it
> is just to check each character node and discard the ones you don't want.
> Except in unusual circumstances where EOL doesn't get considered as
> whitespace, the EOLs will get trimmed.
   I'm not quite sure what's needed here, either, but I'd guess that
the goal is to get the contents of the element, as with (data), minus
the trailing whitespace.  Perhaps something like:

(define ws '(#\U-0009 #\U-000A #\U-000D #\U-0020))
(define data-trim (lambda (#!optional (nd (current-node)))
  (let ((s (data nd))) (let loop ((l (string-length s)))
    (cond ((= l 0) "") ((member (string-ref s (- l 1)) ws) (loop (- l 1)))
          (else (substring s 0 l)))))))

   Note that this only strips the whitespace at the end, though it
could be modified without too much trouble to strip it at both ends.
Note, also, that I used "Unicode" syntax to specify my whitespace
characters, first because Jade has no character name for tab built in
(though, it looks like it would pick it up, if the SGML declaration
specifically named it...?), and second because earlier versions
didn't have line-feed or carriage-return.  The definition of
whitespace can, of course, be changed to taste (so you can do
whatever you want with EOL).
   And, the standard disclaimer... this hasn't been tested. :)

-Brandon :)

 DSSSList info and archive:

Current Thread