Changeset 18006 in project


Ignore:
Timestamp:
05/06/10 20:04:17 (9 years ago)
Author:
Jim Ursetto
Message:

chicken-doc-admin: Concatenate table string fragments, fixing inline across char entities

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/chicken-doc-admin/trunk/svnwiki-sxml.scm

    r17975 r18006  
    1111(import (only ports with-input-from-port))
    1212(import (only data-structures string-intersperse string-split))
    13 (import (only srfi-13 string-trim-right string-trim-both))
     13(import (only srfi-13 string-trim-right string-trim-both
     14              string-concatenate-reverse))
    1415(use regex)
    1516(use matchable)
     
    257258                                            (proc str)))
    258259                               (*default* . ,(lambda x x)))))
     260
     261(define (concatenate-string-fragments L)
     262  ;; Intentional: Does not omit empty strings after collapse.
     263  (define (str-concat s) ; requires: s is pair
     264    (if (null? (cdr L))
     265        s                               ; no fresh copy needed
     266        (string-concatenate-reverse s)))
     267  (define (scons s L)
     268    (if (null? s)
     269        L
     270        (cons (str-concat s) L)))
     271  (let rec ((L L) (str '()))
     272    (cond ((null? L)
     273           (scons str '()))
     274          ((pair? (car L))
     275           (scons str
     276                  (cons (rec (car L) '())
     277                        (rec (cdr L) '()))))
     278          ((string? (car L))
     279           (rec (cdr L)
     280                (cons (car L) str)))
     281          (else
     282           (scons str
     283                  (cons (car L)
     284                        (rec (cdr L) '())))))))
     285
    259286(define table
    260287  (match-lambda ((_ tag ln)
     
    262289            (let* ((table-str (string-append tag (read-verbatim re:table-tag-end ln)))
    263290                   (table-sxml (cadr (html->sxml table-str))))
    264               ;; Transform inline elements in strings.  Fails when open/close pair
    265               ;; crosses strings.  Usual failure case is interceding char entity.
    266               (pre-post-order-text table-sxml inline)))))
     291              ;; Transform inline elements in strings.  char entities open a
     292              ;; new string and transform does not work across string boundaries,
     293              ;; so first concatenate any adjacent string fragments in the sxml.
     294              (pre-post-order-text (concatenate-string-fragments table-sxml)
     295                                   inline)))))
    267296
    268297;;; block start tag to end tag reading
Note: See TracChangeset for help on using the changeset viewer.