fix scribble output when a table appears as the first thing in an itemization item; a little more mzlib scribblings

svn: r8617

original commit: 9bfa156f91656007ac2af9b1af48fe3b01bd094e
This commit is contained in:
Matthew Flatt 2008-02-11 12:55:30 +00:00
parent 1d65736113
commit 6523d4e723
4 changed files with 51 additions and 42 deletions

View File

@ -298,7 +298,7 @@
(list
(when (part-title-content d)
(render-content (part-title-content d) d ri))
(render-flow (part-flow d) d ri)
(render-flow (part-flow d) d ri #f)
(map (lambda (s) (render-part s ri))
(part-parts d))))
@ -308,36 +308,41 @@
(define/public (render-paragraph p part ri)
(render-content (paragraph-content p) part ri))
(define/public (render-flow p part ri)
(apply append
(map (lambda (p)
(render-flow-element p part ri))
(flow-paragraphs p))))
(define/public (render-flow p part ri start-inline?)
(if (null? (flow-paragraphs p))
null
(append
(render-flow-element (car (flow-paragraphs p))
part ri start-inline?)
(apply append
(map (lambda (p)
(render-flow-element p part ri #f))
(cdr (flow-paragraphs p)))))))
(define/public (render-flow-element p part ri)
(define/public (render-flow-element p part ri inline?)
(cond
[(table? p) (if (auxiliary-table? p)
(render-auxiliary-table p part ri)
(render-table p part ri))]
(render-table p part ri inline?))]
[(itemization? p) (render-itemization p part ri)]
[(blockquote? p) (render-blockquote p part ri)]
[(delayed-flow-element? p)
(render-flow-element (delayed-flow-element-flow-elements p ri) part ri)]
(render-flow-element (delayed-flow-element-flow-elements p ri) part ri inline?)]
[else (render-paragraph p part ri)]))
(define/public (render-auxiliary-table i part ri)
null)
(define/public (render-table i part ri)
(map (lambda (d) (if (flow? i) (render-flow d part ri) null))
(define/public (render-table i part ri inline?)
(map (lambda (d) (if (flow? i) (render-flow d part ri #f) null))
(apply append (table-flowss i))))
(define/public (render-itemization i part ri)
(map (lambda (d) (render-flow d part ri))
(map (lambda (d) (render-flow d part ri #t))
(itemization-flows i)))
(define/public (render-blockquote i part ri)
(map (lambda (d) (render-flow-element d part ri))
(map (lambda (d) (render-flow-element d part ri #f))
(blockquote-paragraphs i)))
(define/public (render-element i part ri)

View File

@ -331,7 +331,7 @@
(map (lambda (t)
(let loop ([t t])
(if (table? t)
(render-table t d ri)
(render-table t d ri #f)
(loop (delayed-flow-element-flow-elements t ri)))))
(filter (lambda (e)
(let loop ([e e])
@ -620,7 +620,7 @@
,@(if (part-title-content d)
(render-content (part-title-content d) d ri)
null)))))
,@(render-flow* (part-flow d) d ri #f)
,@(render-flow* (part-flow d) d ri #f #f)
,@(let loop ([pos 1]
[secs (part-parts d)])
(if (null? secs)
@ -629,23 +629,23 @@
(render-part (car secs) ri)
(loop (add1 pos) (cdr secs))))))))
(define/private (render-flow* p part ri special-last?)
(define/private (render-flow* p part ri start-inline? special-last?)
;; Wrap each table with <p>, except for a trailing table
;; when `special-last?' is #t
(let loop ([f (flow-paragraphs p)])
(let loop ([f (flow-paragraphs p)][inline? start-inline?])
(cond
[(null? f) null]
[(and (table? (car f))
(or (not special-last?)
(not (null? (cdr f)))))
(cons `(p ,@(render-flow-element (car f) part ri))
(loop (cdr f)))]
(cons `(p ,@(render-flow-element (car f) part ri inline?))
(loop (cdr f) #f))]
[else
(append (render-flow-element (car f) part ri)
(loop (cdr f)))])))
(append (render-flow-element (car f) part ri inline?)
(loop (cdr f) #f))])))
(define/override (render-flow p part ri)
(render-flow* p part ri #t))
(define/override (render-flow p part ri start-inline?)
(render-flow* p part ri start-inline? #t))
(define/override (render-paragraph p part ri)
`((p ,@(if (styled-paragraph? p)
@ -751,10 +751,13 @@
[(image-file? style) `((img ((src ,(install-file (image-file-path style))))))]
[else (super render-element e part ri)])))
(define/override (render-table t part ri)
(define/override (render-table t part ri need-inline?)
(define index? (eq? 'index (table-style t)))
`(,@(if index? `(,search-script ,search-field) '())
(table ((cellspacing "0")
,@(if need-inline?
'((style "display: inline; vertical-align: top;"))
null)
,@(case (table-style t)
[(boxed) '((class "boxed"))]
[(centered) '((align "center"))]
@ -810,7 +813,7 @@
[(eq? 'cont (car ds)) (loop (+ n 1) (cdr ds))]
[else n])))))
null))
,@(render-flow d part ri))
,@(render-flow d part ri #f))
(loop (cdr ds) (cdr as) (cdr vas)))))))))
(table-flowss t)
(cdr (or (and (list? (table-style t))
@ -823,7 +826,7 @@
null)
,@(apply append
(map (lambda (i)
(render-flow-element i part ri))
(render-flow-element i part ri #f))
(blockquote-paragraphs t))))))
(define/override (render-itemization t part ri)
@ -833,7 +836,7 @@
`(((class ,(styled-itemization-style t))))
null)
,@(map (lambda (flow)
`(li ,@(render-flow flow part ri)))
`(li ,@(render-flow flow part ri #t)))
(itemization-flows t)))))
(define/override (render-other i part ri)

View File

@ -113,7 +113,7 @@
(for-each (lambda (t)
(printf "\\label{t:~a}" (t-encode (tag-key t ri))))
(part-tags d))
(render-flow (part-flow d) d ri)
(render-flow (part-flow d) d ri #f)
(for-each (lambda (sec) (render-part sec ri))
(part-parts d))
null))
@ -226,7 +226,7 @@
(format "x~x" (char->integer c))]))
(string->list (format "~s" s)))))
(define/override (render-table t part ri)
(define/override (render-table t part ri inline-table?)
(let* ([boxed? (eq? 'boxed (table-style t))]
[index? (eq? 'index (table-style t))]
[inline? (and (not boxed?)
@ -239,7 +239,8 @@
(= 1 (length (car (table-flowss (cadr m))))))))]
[tableform (cond
[index? "list"]
[(not (current-table-mode))
[(and (not (current-table-mode))
(not inline-table?))
"longtable"]
[else "tabular"])]
[opt (cond
@ -299,7 +300,7 @@
[else n]))])
(unless (= cnt 1)
(printf "\\multicolumn{~a}{l}{" cnt))
(render-flow (car flows) part ri)
(render-flow (car flows) part ri #f)
(unless (= cnt 1)
(printf "}"))
(unless (null? (list-tail flows cnt))
@ -325,7 +326,7 @@
(printf "\n\n\\begin{itemize}\n")
(for-each (lambda (flow)
(printf "\n\n\\item ")
(render-flow flow part ri))
(render-flow flow part ri #t))
(itemization-flows t))
(printf "\n\n\\end{itemize}\n")
null)
@ -334,7 +335,7 @@
(printf "\n\n\\begin{quote}\n")
(parameterize ([current-table-mode (list "blockquote" t)])
(for-each (lambda (e)
(render-flow-element e part ri))
(render-flow-element e part ri #f))
(blockquote-paragraphs t)))
(printf "\n\n\\end{quote}\n")
null)

View File

@ -34,7 +34,7 @@
(part-title-content d))
(newline))
(newline)
(render-flow (part-flow d) d ht)
(render-flow (part-flow d) d ht #f)
(let loop ([pos 1]
[secs (part-parts d)])
(unless (null? secs)
@ -42,28 +42,28 @@
(render-part (car secs) ht)
(loop (add1 pos) (cdr secs))))))
(define/override (render-flow f part ht)
(define/override (render-flow f part ht start-inline?)
(let ([f (flow-paragraphs f)])
(if (null? f)
null
(apply
append
(render-flow-element (car f) part ht)
(render-flow-element (car f) part ht start-inline?)
(map (lambda (p)
(newline) (newline)
(render-flow-element p part ht))
(render-flow-element p part ht #f))
(cdr f))))))
(define/override (render-table i part ht)
(define/override (render-table i part ht inline?)
(let ([flowss (table-flowss i)])
(if (null? flowss)
null
(apply
append
(map (lambda (d) (render-flow d part ht)) (car flowss))
(map (lambda (d) (render-flow d part ht #f)) (car flowss))
(map (lambda (flows)
(newline)
(map (lambda (d) (render-flow d part ht)) flows))
(map (lambda (d) (render-flow d part ht #f)) flows))
(cdr flowss))))))
(define/override (render-itemization i part ht)
@ -73,10 +73,10 @@
(apply append
(begin
(printf "* ")
(render-flow (car flows) part ht))
(render-flow (car flows) part ht #t))
(map (lambda (d)
(printf "\n\n* ")
(render-flow d part ht))
(render-flow d part ht #f))
(cdr flows))))))
(define/override (render-other i part ht)