diff --git a/collects/scribble/base-render.ss b/collects/scribble/base-render.ss index 0c7865db..caad1abd 100644 --- a/collects/scribble/base-render.ss +++ b/collects/scribble/base-render.ss @@ -150,14 +150,14 @@ (define/public (collect-flow p ci) (for ([p (flow-paragraphs p)]) - (collect-flow-element p ci))) + (collect-block p ci))) - (define/public (collect-flow-element p ci) + (define/public (collect-block p ci) (cond [(table? p) (collect-table p ci)] [(itemization? p) (collect-itemization p ci)] [(blockquote? p) (collect-blockquote p ci)] - [(delayed-flow-element? p) (void)] + [(delayed-block? p) (void)] [else (collect-paragraph p ci)])) (define/public (collect-table i ci) @@ -170,7 +170,7 @@ (define/public (collect-blockquote i ci) (for ([d (blockquote-paragraphs i)]) - (collect-flow-element d ci))) + (collect-block d ci))) (define/public (collect-element i ci) (if (part-relative-element? i) @@ -230,17 +230,17 @@ (define/public (resolve-flow p d ri) (for ([p (flow-paragraphs p)]) - (resolve-flow-element p d ri))) + (resolve-block p d ri))) - (define/public (resolve-flow-element p d ri) + (define/public (resolve-block p d ri) (cond [(table? p) (resolve-table p d ri)] [(itemization? p) (resolve-itemization p d ri)] [(blockquote? p) (resolve-blockquote p d ri)] - [(delayed-flow-element? p) - (let ([v ((delayed-flow-element-resolve p) this d ri)]) + [(delayed-block? p) + (let ([v ((delayed-block-resolve p) this d ri)]) (hash-table-put! (resolve-info-delays ri) p v) - (resolve-flow-element v d ri))] + (resolve-block v d ri))] [else (resolve-paragraph p d ri)])) (define/public (resolve-table i d ri) @@ -253,7 +253,7 @@ (define/public (resolve-blockquote i d ri) (for ([f (blockquote-paragraphs i)]) - (resolve-flow-element f d ri))) + (resolve-block f d ri))) (define/public (resolve-element i d ri) (cond @@ -315,22 +315,22 @@ (if (null? (flow-paragraphs p)) null (append - (render-flow-element (car (flow-paragraphs p)) + (render-block (car (flow-paragraphs p)) part ri start-inline?) (apply append (map (lambda (p) - (render-flow-element p part ri #f)) + (render-block p part ri #f)) (cdr (flow-paragraphs p))))))) - (define/public (render-flow-element p part ri inline?) + (define/public (render-block p part ri inline?) (cond [(table? p) (if (auxiliary-table? p) (render-auxiliary-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 inline?)] + [(delayed-block? p) + (render-block (delayed-block-blocks p ri) part ri inline?)] [else (render-paragraph p part ri)])) (define/public (render-auxiliary-table i part ri) @@ -345,7 +345,7 @@ (itemization-flows i))) (define/public (render-blockquote i part ri) - (map (lambda (d) (render-flow-element d part ri #f)) + (map (lambda (d) (render-block d part ri #f)) (blockquote-paragraphs i))) (define/public (render-element i part ri) diff --git a/collects/scribble/basic.ss b/collects/scribble/basic.ss index 2f809684..9ce13cb0 100644 --- a/collects/scribble/basic.ss +++ b/collects/scribble/basic.ss @@ -162,7 +162,7 @@ ;; ---------------------------------------- -(provide section-index index index* as-index index-section index-flow-elements) +(provide section-index index index* as-index index-section index-blocks) (define (section-index . elems) (make-part-index-decl (map element->string elems) elems)) @@ -199,10 +199,10 @@ (list title) 'index null - (make-flow (index-flow-elements)) + (make-flow (index-blocks)) null)) -(define (index-flow-elements) +(define (index-blocks) (define (commas l) (if (or (null? l) (null? (cdr l))) l @@ -277,7 +277,7 @@ (list e)))] [else e])) l))))) - (list (make-delayed-flow-element contents))) + (list (make-delayed-block contents))) ;; ---------------------------------------- @@ -285,11 +285,11 @@ local-table-of-contents) (define (table-of-contents) - (make-delayed-flow-element + (make-delayed-block (lambda (renderer part ri) (send renderer table-of-contents part ri)))) (define (local-table-of-contents) - (make-delayed-flow-element + (make-delayed-block (lambda (renderer part ri) (send renderer local-table-of-contents part ri)))) diff --git a/collects/scribble/decode.ss b/collects/scribble/decode.ss index 3e073bcc..6388f6b0 100644 --- a/collects/scribble/decode.ss +++ b/collects/scribble/decode.ss @@ -10,6 +10,7 @@ decode-flow decode-paragraph decode-content + (rename decode-content decode-elements) decode-string whitespace?) @@ -105,7 +106,7 @@ (title-decl-tags (car l)) (title-decl-version (car l)) (title-decl-style (car l)))])] - [(flow-element? (car l)) + [(block? (car l)) (let ([para (decode-accum-para accum)] [part (decode-flow* (cdr l) keys colls tag-prefix tags vers style title part-depth)]) diff --git a/collects/scribble/html-render.ss b/collects/scribble/html-render.ss index 919bbe24..ecb076f1 100644 --- a/collects/scribble/html-render.ss +++ b/collects/scribble/html-render.ss @@ -181,7 +181,7 @@ (define (render-mixin %) (class % (inherit render-content - render-flow-element + render-block collect-part install-file get-dest-directory @@ -337,13 +337,13 @@ (let loop ([t t]) (if (table? t) (render-table t d ri #f) - (loop (delayed-flow-element-flow-elements t ri))))) + (loop (delayed-block-blocks t ri))))) (filter (lambda (e) (let loop ([e e]) (or (and (auxiliary-table? e) (pair? (table-flowss e))) - (and (delayed-flow-element? e) - (loop (delayed-flow-element-flow-elements e ri)))))) + (and (delayed-block? e) + (loop (delayed-block-blocks e ri)))))) (flow-paragraphs (part-flow d)))))))))) (define/public (get-onthispage-label) @@ -368,8 +368,8 @@ ;; get internal targets: (letrec ([flow-targets (lambda (flow) - (apply append (map flow-element-targets (flow-paragraphs flow))))] - [flow-element-targets + (apply append (map block-targets (flow-paragraphs flow))))] + [block-targets (lambda (e) (cond [(table? e) (table-targets e)] @@ -377,8 +377,8 @@ [(itemization? e) (apply append (map flow-targets (itemization-flows e)))] [(blockquote? e) - (apply append (map flow-element-targets (blockquote-paragraphs e)))] - [(delayed-flow-element? e) + (apply append (map block-targets (blockquote-paragraphs e)))] + [(delayed-block? e) null]))] [para-targets (lambda (para) @@ -412,7 +412,7 @@ (flow-targets f))) flows))) (table-flowss table))))]) - (apply append (map flow-element-targets (flow-paragraphs (part-flow d))))) + (apply append (map block-targets (flow-paragraphs (part-flow d))))) (map flatten (part-parts d)))))] [any-parts? (ormap part? ps)]) (if (null? ps) @@ -647,10 +647,10 @@ [(and (table? (car f)) (or (not special-last?) (not (null? (cdr f))))) - (cons `(p ,@(render-flow-element (car f) part ri inline?)) + (cons `(p ,@(render-block (car f) part ri inline?)) (loop (cdr f) #f))] [else - (append (render-flow-element (car f) part ri inline?) + (append (render-block (car f) part ri inline?) (loop (cdr f) #f))]))) (define/override (render-flow p part ri start-inline?) @@ -757,7 +757,26 @@ [(url-anchor? style) `((a ((name ,(url-anchor-name style))) ,@(super render-element e part ri)))] - [(image-file? style) `((img ((src ,(install-file (image-file-path style))))))] + [(image-file? style) + (let* ([src (image-file-path style)] + [scale (image-file-scale style)] + [sz (if (= 1.0 scale) + null + ;; Try to extract file size: + (call-with-input-file* + src + (lambda (in) + (if (regexp-try-match #px#"^\211PNG.{12}" in) + (let ([w (read-bytes 4 in)] + [h (read-bytes 4 in)] + [to-num (lambda (s) + (number->string + (inexact->exact + (floor (* scale (integer-bytes->integer s #f #t))))))]) + `((width ,(to-num w)) + (height ,(to-num h)))) + null))))]) + `((img ((src ,(install-file src)) ,@sz))))] [else (super render-element e part ri)]))) (define/override (render-table t part ri need-inline?) @@ -835,7 +854,7 @@ null) ,@(apply append (map (lambda (i) - (render-flow-element i part ri #f)) + (render-block i part ri #f)) (blockquote-paragraphs t)))))) (define/override (render-itemization t part ri) diff --git a/collects/scribble/latex-render.ss b/collects/scribble/latex-render.ss index ef126af3..719b811b 100644 --- a/collects/scribble/latex-render.ss +++ b/collects/scribble/latex-render.ss @@ -22,7 +22,7 @@ (define/override (get-suffix) #".tex") (inherit render-flow - render-flow-element + render-block render-content install-file format-number) @@ -297,7 +297,7 @@ (printf "\n\n\\begin{~a}\n" kind) (parameterize ([current-table-mode (list "blockquote" t)]) (for-each (lambda (e) - (render-flow-element e part ri #f)) + (render-block e part ri #f)) (blockquote-paragraphs t))) (printf "\n\n\\end{~a}\n" kind) null)) diff --git a/collects/scribble/manual.ss b/collects/scribble/manual.ss index e8b7db2e..23805328 100644 --- a/collects/scribble/manual.ss +++ b/collects/scribble/manual.ss @@ -1243,7 +1243,7 @@ ;; multiple results (if (null? res) 'nbsp - (let ([w (apply max 0 (map flow-element-width res))]) + (let ([w (apply max 0 (map block-width res))]) (if (or (ormap table? res) (w . > . 30)) (make-table @@ -1266,7 +1266,7 @@ (+ (prototype-size args max max) (prototype-depth prototype) (element-width tagged))) - (flow-element-width res)) + (block-width res)) . >= . (- max-proto-width 7))] [(end) (list (to-flow spacer) (to-flow 'rarr) @@ -1365,10 +1365,10 @@ [(not (arg-special? arg)) (let* ([arg-cont (arg-contract)] [base-len (+ 5 (string-length (symbol->string (arg-id arg))) - (flow-element-width arg-cont))] + (block-width arg-cont))] [arg-val (and arg-val (arg-val))] [def-len (if (arg-optional? arg) - (flow-element-width arg-val) + (block-width arg-val) 0)] [base-list (list @@ -1675,7 +1675,7 @@ spacer ":" spacer)))) (make-flow (list - (if (flow-element? result-contract) + (if (block? result-contract) result-contract (make-paragraph (list result-contract))))))))))) stx-ids names result-contracts)) @@ -2174,7 +2174,7 @@ [else i])) body) (list - (make-delayed-flow-element + (make-delayed-block (lambda (r d ri) (make-inherited-table r d ri decl)))))) diff --git a/collects/scribble/struct.ss b/collects/scribble/struct.ss index 083f9e7a..53d707c8 100644 --- a/collects/scribble/struct.ss +++ b/collects/scribble/struct.ss @@ -123,13 +123,13 @@ (list? (cadr s)))) (null? (cddr s)))) - (provide flow-element?) - (define (flow-element? p) + (provide block?) + (define (block? p) (or (paragraph? p) (table? p) (itemization? p) (blockquote? p) - (delayed-flow-element? p))) + (delayed-block? p))) (provide-structs [part ([tag-prefix (or/c false/c string?)] @@ -141,17 +141,17 @@ [parts (listof part?)])] [(unnumbered-part part) ()] [(versioned-part part) ([version (or/c string? false/c)])] - [flow ([paragraphs (listof flow-element?)])] + [flow ([paragraphs (listof block?)])] [paragraph ([content list?])] [(styled-paragraph paragraph) ([style any/c])] [table ([style any/c] [flowss (listof (listof (or/c flow? (one-of/c 'cont))))])] [(auxiliary-table table) ()] - [delayed-flow-element ([resolve (any/c part? resolve-info? . -> . flow-element?)])] + [delayed-block ([resolve (any/c part? resolve-info? . -> . block?)])] [itemization ([flows (listof flow?)])] [(styled-itemization itemization) ([style any/c])] [blockquote ([style any/c] - [paragraphs (listof flow-element?)])] + [paragraphs (listof block?)])] ;; content = list of elements [element ([style any/c] [content list?])] @@ -213,8 +213,8 @@ (define (delayed-element-content e ri) (hash-table-get (resolve-info-delays ri) e)) - (provide delayed-flow-element-flow-elements) - (define (delayed-flow-element-flow-elements p ri) + (provide delayed-block-blocks) + (define (delayed-block-blocks p ri) (hash-table-get (resolve-info-delays ri) p)) (provide current-serialize-resolve-info) @@ -429,7 +429,7 @@ ;; ---------------------------------------- - (provide flow-element-width + (provide block-width element-width) (define (element-width s) @@ -444,15 +444,15 @@ (apply + (map element-width (paragraph-content s)))) (define (flow-width f) - (apply max 0 (map flow-element-width (flow-paragraphs f)))) + (apply max 0 (map block-width (flow-paragraphs f)))) - (define (flow-element-width p) + (define (block-width p) (cond [(paragraph? p) (paragraph-width p)] [(table? p) (table-width p)] [(itemization? p) (itemization-width p)] [(blockquote? p) (blockquote-width p)] - [(delayed-flow-element? p) 1])) + [(delayed-block? p) 1])) (define (table-width p) (let ([flowss (table-flowss p)]) diff --git a/collects/scribble/text-render.ss b/collects/scribble/text-render.ss index 2c078dd1..79aa1f50 100644 --- a/collects/scribble/text-render.ss +++ b/collects/scribble/text-render.ss @@ -17,7 +17,7 @@ (inherit render-content render-paragraph - render-flow-element) + render-block) (define/override (render-part d ht) (let ([number (collected-info-number (part-collected-info d ht))]) @@ -50,10 +50,10 @@ null (apply append - (render-flow-element (car f) part ht start-inline?) + (render-block (car f) part ht start-inline?) (map (lambda (p) (newline) (newline) - (render-flow-element p part ht #f)) + (render-block p part ht #f)) (cdr f)))))) (define/override (render-table i part ht inline?) diff --git a/collects/scribblings/scribble/decode.scrbl b/collects/scribblings/scribble/decode.scrbl index ba6e648f..da1ccc9d 100644 --- a/collects/scribblings/scribble/decode.scrbl +++ b/collects/scribblings/scribble/decode.scrbl @@ -93,6 +93,11 @@ Decodes a sequence of elements. } +@defproc[(decode-elements [lst list?]) list?]{ + +An alias for @scheme[decode-content]. +} + @defproc[(decode-string [s string?]) list?]{ Decodes a single string to produce a list of elements. diff --git a/collects/scribblings/scribble/struct.scrbl b/collects/scribblings/scribble/struct.scrbl index 35bec8e7..18632576 100644 --- a/collects/scribblings/scribble/struct.scrbl +++ b/collects/scribblings/scribble/struct.scrbl @@ -37,11 +37,11 @@ A @deftech{part} is an instance of @scheme[part]; among other things, subsection (incorporated via @scheme[include-section]) as a document. A @deftech{flow} is an instance of @scheme[flow]; it has a list of - @techlink{flow elements}. + @techlink{blocks}. -A @deftech{flow element} is either a @techlink{table}, an +A @deftech{block} is either a @techlink{table}, an @techlink{itemization}, @techlink{blockquote}, @techlink{paragraph}, - or a @techlink{delayed flow element}. + or a @techlink{delayed block}. @itemize{ @@ -54,7 +54,7 @@ A @deftech{flow element} is either a @techlink{table}, an it has a list of @techlink{flows}.} @item{A @deftech{blockquote} is an instance of - @scheme[blockquote]; it has list of @tech{flow elements} + @scheme[blockquote]; it has list of @tech{blocks} that are indented according to a specified style.} @item{A @deftech{paragraph} is an instance of @@ -144,10 +144,10 @@ A @deftech{flow element} is either a @techlink{table}, an }}}} - @item{A @deftech{delayed flow element} is an instance of - @scheme[delayed-flow-element], which has a procedure that + @item{A @deftech{delayed block} is an instance of + @scheme[delayed-block], which has a procedure that is called in the @techlink{resolve pass} of document - processing to obtain a @defterm{flow element}.} + processing to obtain a @defterm{block}.} } @@ -212,7 +212,7 @@ can be extracted with @scheme[part-collected-info], which includes a part's number and its parent part (or @scheme[#f]). More generally, the @scheme[resolve-get] method looks up information previously collected. This resolve-time information is normally obtained by the -procedure associated with a @techlink{delayed flow element} or +procedure associated with a @techlink{delayed block} or @techlink{delayed element}. The @scheme[resolve-get] information accepts both a @scheme[part] and @@ -292,7 +292,7 @@ representing the whole document. The default version for a document is @defstruct[flow ([paragraphs (listof flow-element?)])]{ -A @techlink{flow} has a list of @tech{flow elements}. +A @techlink{flow} has a list of @tech{blocks}. } @@ -330,16 +330,16 @@ A @techlink{itemization} has a list of flows. @defstruct[blockquote ([style any/c] [paragraphs (listof flow-element?)])]{ -A @techlink{blockquote} has a style and a list of @tech{flow -elements}. The @scheme[style] field is normally a string that -corresponds to a CSS class for HTML output. +A @techlink{blockquote} has a style and a list of @tech{blocks}. The +@scheme[style] field is normally a string that corresponds to a CSS +class for HTML output. } -@defstruct[delayed-flow-element ([resolve (any/c part? resolve-info? . -> . flow-element?)])]{ +@defstruct[delayed-block ([resolve (any/c part? resolve-info? . -> . flow-element?)])]{ The @scheme[resolve] procedure is called during the @techlink{resolve -pass} to obtain a normal @tech{flow element}. The first argument to +pass} to obtain a normal @tech{block}. The first argument to @scheme[resolve] is the renderer. } @@ -448,8 +448,8 @@ Instances of this structure type are intended for use in titles, where [plain (-> any/c)])]{ The @scheme[render] procedure's arguments are the same as for -@scheme[delayed-flow-element], but the result is @techlink{content} (i.e., -a list of @techlink{elements}). Unlike @scheme[delayed-flow-element], the +@scheme[delayed-block], but the result is @techlink{content} (i.e., +a list of @techlink{elements}). Unlike @scheme[delayed-block], the result of the @scheme[render] procedure's argument is remembered on the first call for re-use for a particular resolve pass. @@ -469,7 +469,7 @@ pass}. [sizer (-> any/c)] [plain (-> any/c)])]{ -Similar to @scheme[delayed-flow-element], but the replacement +Similar to @scheme[delayed-block], but the replacement @techlink{content} is obtained in the @techlink{collect pass} by calling the function in the @scheme[resolve] field. @@ -512,16 +512,17 @@ Used as a style for an @scheme[element]. The @scheme[style] at this layer is a style for the hyperlink.} -@defstruct[image-file ([path path-string?])]{ +@defstruct[image-file ([path path-string?] + [scale real?])]{ Used as a style for an @scheme[element].} -@defproc[(flow-element? [v any/c]) boolean?]{ +@defproc[(block? [v any/c]) boolean?]{ Returns @scheme[#t] if @scheme[v] is a @scheme[paragraph], @scheme[table], @scheme[itemization], @scheme[blockquote], or -@scheme[delayed-flow-element], @scheme[#f] otherwise. +@scheme[delayed-block], @scheme[#f] otherwise. } @@ -569,9 +570,9 @@ Returns the width in characters of the given @tech{element}. } -@defproc[(flow-element-width (e flow-element?)) nonnegative-exact-integer?]{ +@defproc[(block-width (e block?)) nonnegative-exact-integer?]{ -Returns the width in characters of the given @tech{flow element}.} +Returns the width in characters of the given @tech{block}.} @defstruct[collect-info ([ht any/c] [ext-ht any/c] [parts any/c] diff --git a/collects/scribblings/scribble/utils.ss b/collects/scribblings/scribble/utils.ss index e2b15c5d..a1f581a0 100644 --- a/collects/scribblings/scribble/utils.ss +++ b/collects/scribblings/scribble/utils.ss @@ -41,7 +41,7 @@ strs))))) (define (as-flow e) - (make-flow (list (if (flow-element? e) + (make-flow (list (if (block? e) e (make-paragraph (list e))))))