diff --git a/collects/scribble/base-render.ss b/collects/scribble/base-render.ss index 397c8549..e918f79d 100644 --- a/collects/scribble/base-render.ss +++ b/collects/scribble/base-render.ss @@ -11,7 +11,7 @@ (class object% (init-field dest-dir) - + (define/public (get-dest-directory) dest-dir) @@ -42,210 +42,334 @@ [else (cons (car content) (strip-aux (cdr content)))])) + ;; ---------------------------------------- + ;; marshal info + + (define/public (get-serialize-version) + 1) + + (define/public (serialize-info ri) + (parameterize ([current-serialize-resolve-info ri]) + (serialize (collect-info-ht (resolve-info-ci ri))))) + + (define/public (deserialize-info v ci) + (let ([ht (deserialize v)] + [in-ht (collect-info-ext-ht ci)]) + (hash-table-for-each ht (lambda (k v) + (hash-table-put! in-ht k v))))) + (define/public (get-defined ci) + (hash-table-map (collect-info-ht ci) (lambda (k v) k))) + + (define/public (get-undefined ri) + (hash-table-map (resolve-info-undef ri) (lambda (k v) k))) + ;; ---------------------------------------- ;; global-info collection - (define/public (save-info fn info) - (let ([s (serialize info)]) - (with-output-to-file fn - (lambda () - (write s)) - 'truncate/replace))) - - (define/public (load-info fn info) - (let ([ht (deserialize (with-input-from-file fn read))]) - (hash-table-for-each ht (lambda (k v) - (hash-table-put! info k v)))) - info) - (define/public (collect ds fns) - (let ([ht (make-hash-table 'equal)]) - (map (lambda (d) - (collect-part d #f ht null)) - ds) - ht)) + (let ([ci (make-collect-info (make-hash-table 'equal) + (make-hash-table 'equal) + (make-hash-table) + (make-hash-table) + "")]) + (start-collect ds fns ci) + ci)) - (define/public (collect-part d parent ht number) - (let ([p-ht (make-hash-table 'equal)]) + (define/public (start-collect ds fns ci) + (map (lambda (d) + (collect-part d #f ci null)) + ds)) + + (define/public (collect-part d parent ci number) + (let ([p-ci (make-collect-info (make-hash-table 'equal) + (collect-info-ext-ht ci) + (collect-info-parts ci) + (collect-info-tags ci) + (if (part-tag-prefix d) + (string-append (collect-info-gen-prefix ci) + (part-tag-prefix d) + ":") + (collect-info-gen-prefix ci)))]) (when (part-title-content d) - (collect-content (part-title-content d) p-ht)) - (collect-part-tags d p-ht number) - (collect-content (part-to-collect d) p-ht) - (collect-flow (part-flow d) p-ht) + (collect-content (part-title-content d) p-ci)) + (collect-part-tags d p-ci number) + (collect-content (part-to-collect d) p-ci) + (collect-flow (part-flow d) p-ci) (let loop ([parts (part-parts d)] [pos 1]) (unless (null? parts) (let ([s (car parts)]) - (collect-part s d p-ht + (collect-part s d p-ci (cons (if (unnumbered-part? s) #f pos) number)) (loop (cdr parts) (if (unnumbered-part? s) pos (add1 pos)))))) - (set-part-collected-info! d (make-collected-info - number - parent - p-ht)) - (hash-table-for-each p-ht - (lambda (k v) - (hash-table-put! ht k v))))) + (hash-table-put! (collect-info-parts ci) + d + (make-collected-info + number + parent + (collect-info-ht p-ci))) + (let ([prefix (part-tag-prefix d)]) + (hash-table-for-each (collect-info-ht p-ci) + (lambda (k v) + (when (cadr k) + (hash-table-put! (collect-info-ht ci) + (if prefix + (convert-key prefix k) + k) + v))))))) - (define/public (collect-part-tags d ht number) + (define/private (convert-key prefix k) + (case (car k) + [(part tech) + (if (string? (cadr k)) + (list (car k) + (string-append prefix + ":" + (cadr k))) + k)] + [(index-entry) + (let ([v (convert-key prefix (cadr k))]) + (if (eq? v (cadr k)) + k + (list 'index-entry v)))] + [else k])) + + (define/public (collect-part-tags d ci number) (for-each (lambda (t) - (hash-table-put! ht `(part ,t) (list (part-title-content d) number))) + (hash-table-put! (collect-info-ht ci) + (generate-tag t ci) + (list (or (part-title-content d) '("???")) + number))) (part-tags d))) - (define/public (collect-content c ht) + (define/public (collect-content c ci) (for-each (lambda (i) - (collect-element i ht)) + (collect-element i ci)) c)) - (define/public (collect-paragraph p ht) - (collect-content (paragraph-content p) ht)) + (define/public (collect-paragraph p ci) + (collect-content (paragraph-content p) ci)) - (define/public (collect-flow p ht) + (define/public (collect-flow p ci) (for-each (lambda (p) - (collect-flow-element p ht)) + (collect-flow-element p ci)) (flow-paragraphs p))) - (define/public (collect-flow-element p ht) + (define/public (collect-flow-element p ci) (cond - [(table? p) (collect-table p ht)] - [(itemization? p) (collect-itemization p ht)] - [(blockquote? p) (collect-blockquote p ht)] + [(table? p) (collect-table p ci)] + [(itemization? p) (collect-itemization p ci)] + [(blockquote? p) (collect-blockquote p ci)] [(delayed-flow-element? p) (void)] - [else (collect-paragraph p ht)])) + [else (collect-paragraph p ci)])) - (define/public (collect-table i ht) + (define/public (collect-table i ci) (for-each (lambda (d) (when (flow? d) - (collect-flow d ht))) + (collect-flow d ci))) (apply append (table-flowss i)))) - (define/public (collect-itemization i ht) - (for-each (lambda (d) (collect-flow d ht)) + (define/public (collect-itemization i ci) + (for-each (lambda (d) (collect-flow d ci)) (itemization-flows i))) - (define/public (collect-blockquote i ht) - (for-each (lambda (d) (collect-flow-element d ht)) + (define/public (collect-blockquote i ci) + (for-each (lambda (d) (collect-flow-element d ci)) (blockquote-paragraphs i))) - (define/public (collect-element i ht) + (define/public (collect-element i ci) (when (target-element? i) - (collect-target-element i ht)) + (collect-target-element i ci)) (when (index-element? i) - (collect-index-element i ht)) + (collect-index-element i ci)) + (when (collect-element? i) + ((collect-element-collect i) ci)) (when (element? i) (for-each (lambda (e) - (collect-element e ht)) + (collect-element e ci)) (element-content i)))) - (define/public (collect-target-element i ht) - (hash-table-put! ht (target-element-tag i) (list i))) + (define/public (collect-target-element i ci) + (collect-put! ci + (generate-tag (target-element-tag i) ci) + (list i))) - (define/public (collect-index-element i ht) - (hash-table-put! ht `(index-entry ,(index-element-tag i)) - (list (index-element-plain-seq i) - (index-element-entry-seq i)))) + (define/public (collect-index-element i ci) + (collect-put! ci + `(index-entry ,(generate-tag (index-element-tag i) ci)) + (list (index-element-plain-seq i) + (index-element-entry-seq i)))) - (define/public (lookup part ht key) - (let ([v (hash-table-get (if part - (collected-info-info (part-collected-info part)) - ht) - key - #f)]) - (or v - (and part - (lookup (collected-info-parent - (part-collected-info part)) - ht - key))))) + ;; ---------------------------------------- + ;; global-info resolution + + (define/public (resolve ds fns ci) + (let ([ri (make-resolve-info ci + (make-hash-table) + (make-hash-table 'equal))]) + (start-resolve ds fns ri) + ri)) + + (define/public (start-resolve ds fns ri) + (map (lambda (d) + (resolve-part d ri)) + ds)) + + (define/public (resolve-part d ri) + (when (part-title-content d) + (resolve-content (part-title-content d) d ri)) + (resolve-flow (part-flow d) d ri) + (for-each (lambda (p) + (resolve-part p ri)) + (part-parts d))) + + (define/public (resolve-content c d ri) + (for-each (lambda (i) + (resolve-element i d ri)) + c)) + + (define/public (resolve-paragraph p d ri) + (resolve-content (paragraph-content p) d ri)) + + (define/public (resolve-flow p d ri) + (for-each (lambda (p) + (resolve-flow-element p d ri)) + (flow-paragraphs p))) + + (define/public (resolve-flow-element 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)]) + (hash-table-put! (resolve-info-delays ri) p v) + (resolve-flow-element v d ri))] + [else (resolve-paragraph p d ri)])) + + (define/public (resolve-table i d ri) + (for-each (lambda (f) (when (flow? f) + (resolve-flow f d ri))) + (apply append (table-flowss i)))) + + (define/public (resolve-itemization i d ri) + (for-each (lambda (f) (resolve-flow f d ri)) + (itemization-flows i))) + + (define/public (resolve-blockquote i d ri) + (for-each (lambda (f) (resolve-flow-element f d ri)) + (blockquote-paragraphs i))) + + (define/public (resolve-element i d ri) + (cond + [(delayed-element? i) + (resolve-content (or (hash-table-get (resolve-info-delays ri) + i + #f) + (let ([v ((delayed-element-resolve i) this d ri)]) + (hash-table-put! (resolve-info-delays ri) + i + v) + v)) + d ri)] + [(element? i) + (cond + [(link-element? i) + (let-values ([(dest ext?) (resolve-get/where d ri (link-element-tag i))]) + (when ext? + (hash-table-put! (resolve-info-undef ri) + (tag-key (link-element-tag i) ri) + #t)))]) + (for-each (lambda (e) + (resolve-element e d ri)) + (element-content i))])) ;; ---------------------------------------- ;; render methods - (define/public (render ds fns ht) + (define/public (render ds fns ri) (map (lambda (d fn) (printf " [Output to ~a]\n" fn) (with-output-to-file fn (lambda () - (render-one d ht fn)) + (render-one d ri fn)) 'truncate/replace)) - ds fns)) - (define/public (render-one d ht fn) - (render-part d ht)) + (define/public (render-one d ri fn) + (render-part d ri)) - (define/public (render-part d ht) + (define/public (render-part d ri) (list (when (part-title-content d) - (render-content (part-title-content d) d ht)) - (render-flow (part-flow d) d ht) - (map (lambda (s) (render-part s ht)) + (render-content (part-title-content d) d ri)) + (render-flow (part-flow d) d ri) + (map (lambda (s) (render-part s ri)) (part-parts d)))) - (define/public (render-content c part ht) + (define/public (render-content c part ri) (apply append (map (lambda (i) - (render-element i part ht)) + (render-element i part ri)) c))) - (define/public (render-paragraph p part ht) - (render-content (paragraph-content p) part ht)) + (define/public (render-paragraph p part ri) + (render-content (paragraph-content p) part ri)) - (define/public (render-flow p part ht) + (define/public (render-flow p part ri) (apply append (map (lambda (p) - (render-flow-element p part ht)) + (render-flow-element p part ri)) (flow-paragraphs p)))) - (define/public (render-flow-element p part ht) + (define/public (render-flow-element p part ri) (cond [(table? p) (if (auxiliary-table? p) - (render-auxiliary-table p part ht) - (render-table p part ht))] - [(itemization? p) (render-itemization p part ht)] - [(blockquote? p) (render-blockquote p part ht)] - [(delayed-flow-element? p) (render-flow-element - ((delayed-flow-element-render p) this part ht) - part ht)] - [else (render-paragraph p part ht)])) + (render-auxiliary-table p part ri) + (render-table p part ri))] + [(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)] + [else (render-paragraph p part ri)])) - (define/public (render-auxiliary-table i part ht) + (define/public (render-auxiliary-table i part ri) null) - (define/public (render-table i part ht) + (define/public (render-table i part ri) (map (lambda (d) (if (flow? i) - (render-flow d part ht) + (render-flow d part ri) null)) (apply append (table-flowss i)))) - (define/public (render-itemization i part ht) - (map (lambda (d) (render-flow d part ht)) + (define/public (render-itemization i part ri) + (map (lambda (d) (render-flow d part ri)) (itemization-flows i))) - (define/public (render-blockquote i part ht) - (map (lambda (d) (render-flow-element d part ht)) + (define/public (render-blockquote i part ri) + (map (lambda (d) (render-flow-element d part ri)) (blockquote-paragraphs i))) - (define/public (render-element i part ht) + (define/public (render-element i part ri) (cond [(and (link-element? i) (null? (element-content i))) - (let ([v (lookup part ht (link-element-tag i))]) + (let ([v (resolve-get part ri (link-element-tag i))]) (if v - (render-content (strip-aux (car v)) part ht) - (render-content (list "[missing]") part ht)))] + (render-content (strip-aux (car v)) part ri) + (render-content (list "[missing]") part ri)))] [(element? i) - (render-content (element-content i) part ht)] + (render-content (element-content i) part ri)] [(delayed-element? i) - (render-content (force-delayed-element i this part ht) part ht)] + (render-content (delayed-element-content i ri) part ri)] [else - (render-other i part ht)])) + (render-other i part ri)])) - (define/public (render-other i part ht) + (define/public (render-other i part ri) (list i)) ;; ---------------------------------------- @@ -280,34 +404,32 @@ ;; ---------------------------------------- - (define/private (do-table-of-contents part ht delta quiet) - (make-table #f (render-toc part - (+ delta - (length (collected-info-number - (part-collected-info part)))) - #t - quiet))) + (define/private (do-table-of-contents part ri delta quiet) + (make-table #f (generate-toc part + ri + (+ delta + (length (collected-info-number + (part-collected-info part ri)))) + #t + quiet))) - (define/public (table-of-contents part ht) - (do-table-of-contents part ht -1 not)) + (define/public (table-of-contents part ri) + (do-table-of-contents part ri -1 not)) - (define/public (local-table-of-contents part ht) - (table-of-contents part ht)) + (define/public (local-table-of-contents part ri) + (table-of-contents part ri)) - (define/public (quiet-table-of-contents part ht) - (do-table-of-contents part ht 1 (lambda (x) #t))) + (define/public (quiet-table-of-contents part ri) + (do-table-of-contents part ri 1 (lambda (x) #t))) - (define/private (render-toc part base-len skip? quiet) - (let ([number (collected-info-number (part-collected-info part))]) + (define/private (generate-toc part ri base-len skip? quiet) + (let ([number (collected-info-number (part-collected-info part ri))]) (let ([subs - (if (quiet (and (styled-part? part) - (let ([st(styled-part-style part)]) - (or (eq? 'quiet st) - (and (list? st) (memq 'quiet st)))) + (if (quiet (and (part-style? part 'quiet) (not (= base-len (sub1 (length number)))))) (apply append - (map (lambda (p) (render-toc p base-len #f quiet)) (part-parts part))) + (map (lambda (p) (generate-toc p ri base-len #f quiet)) (part-parts part))) null)]) (if skip? subs @@ -324,8 +446,8 @@ (format-number number (list (make-element 'hspace '(" ")))) - (part-title-content part)) - `(part ,(car (part-tags part))))))))) + (or (part-title-content part) '("???"))) + (car (part-tags part)))))))) subs)]) (if (and (= 1 (length number)) (or (not (car number)) diff --git a/collects/scribble/basic.ss b/collects/scribble/basic.ss index 8a60e165..0ec3c1b9 100644 --- a/collects/scribble/basic.ss +++ b/collects/scribble/basic.ss @@ -4,7 +4,9 @@ "struct.ss" "config.ss" (lib "list.ss") - (lib "class.ss")) + (lib "class.ss") + (lib "main-collects.ss" "setup") + (lib "modresolve.ss" "syntax")) (provide title section @@ -18,21 +20,41 @@ (content->string content) "_")) - (define (title #:tag [tag #f] #:style [style #f] . str) + (define (prefix->string p) + (and p + (if (string? p) + p + (module-path-prefix->string p)))) + + (define (title #:tag [tag #f] #:tag-prefix [prefix #f] #:style [style #f] . str) (let ([content (decode-content str)]) - (make-title-decl (or tag (gen-tag content)) style content))) + (make-title-decl (prefix->string prefix) + `((part ,(or tag (gen-tag content)))) + style + content))) - (define (section #:tag [tag #f] #:style [style #f] . str) + (define (section #:tag [tag #f] #:tag-prefix [prefix #f] #:style [style #f] . str) (let ([content (decode-content str)]) - (make-part-start 0 (or tag (gen-tag content)) style content))) + (make-part-start 0 (prefix->string prefix) + `((part ,(or tag (gen-tag content)))) + style + content))) - (define (subsection #:tag [tag #f] . str) + (define (subsection #:tag [tag #f] #:tag-prefix [prefix #f] . str) (let ([content (decode-content str)]) - (make-part-start 1 (or tag (gen-tag content)) #f content))) + (make-part-start 1 + (prefix->string prefix) + `((part ,(or tag (gen-tag content)))) + #f + content))) - (define (subsubsection #:tag [tag #f] . str) + (define (subsubsection #:tag [tag #f] #:tag-prefix [prefix #f] . str) (let ([content (decode-content str)]) - (make-part-start 2 (or tag (gen-tag content)) #f content))) + (make-part-start 2 + (prefix->string prefix) + `((part ,(or tag (gen-tag content)))) + #f + content))) (define (subsubsub*section #:tag [tag #f] . str) (let ([content (decode-content str)]) @@ -47,6 +69,14 @@ ;; ---------------------------------------- + (provide module-path-prefix->string) + + (define (module-path-prefix->string p) + (format "~a" (path->main-collects-relative + (resolve-module-path p #f)))) + + ;; ---------------------------------------- + (provide itemize item item?) (define (itemize . items) @@ -124,19 +154,16 @@ (define (section-index . elems) (make-part-index-decl (map element->string elems) elems)) - (define (gen-target) - (format "index:~s:~s" (current-inexact-milliseconds) (gensym))) - (define (record-index word-seq element-seq tag content) (make-index-element #f - (list (make-target-element #f content tag)) - tag + (list (make-target-element #f content `(idx ,tag))) + `(idx ,tag) word-seq element-seq)) (define (index* word-seq content-seq . s) - (let ([key (gen-target)]) + (let ([key (make-generated-tag)]) (record-index word-seq content-seq key @@ -149,7 +176,7 @@ (apply index* word-seq word-seq s))) (define (as-index . s) - (let ([key (gen-target)] + (let ([key (make-generated-tag)] [content (decode-content s)]) (record-index (list (content->string content)) (list (make-element #f content)) @@ -158,18 +185,21 @@ (define (index-section tag) (make-unnumbered-part - (and tag (list tag)) - (list "Index") #f + `((part , (or tag + (make-generated-tag)))) + '("Index") + 'index null (make-flow (list (make-delayed-flow-element - (lambda (renderer sec ht) + (lambda (renderer sec ri) (let ([l null]) (hash-table-for-each (collected-info-info (part-collected-info (collected-info-parent - (part-collected-info sec)))) + (part-collected-info sec ri)) + ri)) (lambda (k v) (if (and (pair? k) (eq? 'index-entry (car k))) @@ -204,8 +234,7 @@ (commas (caddr i)) (car i)))))))) l)))))))) - null - 'index)) + null)) ;; ---------------------------------------- @@ -214,13 +243,13 @@ (define (table-of-contents) (make-delayed-flow-element - (lambda (renderer part ht) - (send renderer table-of-contents part ht)))) + (lambda (renderer part ri) + (send renderer table-of-contents part ri)))) (define (local-table-of-contents) (make-delayed-flow-element - (lambda (renderer part ht) - (send renderer local-table-of-contents part ht))))) + (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 a21c3ca4..e4a78e9d 100644 --- a/collects/scribble/decode.ss +++ b/collects/scribble/decode.ss @@ -13,16 +13,19 @@ whitespace?) (provide-structs - [title-decl ([tag any/c] + [title-decl ([tag-prefix (or/c false/c string?)] + [tags (listof tag?)] [style any/c] [content list?])] [part-start ([depth integer?] - [tag (or/c false/c string?)] + [tag-prefix (or/c false/c string?)] + [tags (listof tag?)] [style any/c] [title list?])] [splice ([run list?])] [part-index-decl ([plain-seq (listof string?)] - [entry-seq list?])]) + [entry-seq list?])] + [part-collect-decl ([element element?])]) (define (decode-string s) (let loop ([l '((#rx"---" mdash) @@ -52,39 +55,42 @@ null (list (decode-paragraph (reverse (skip-whitespace accum)))))) - (define (decode-flow* l keys tag style title part-depth) - (let loop ([l l][next? #f][keys keys][accum null][title title][tag tag][style style]) + (define (decode-flow* l keys colls tag-prefix tags style title part-depth) + (let loop ([l l][next? #f][keys keys][colls colls][accum null][title title][tag-prefix tag-prefix][tags tags][style style]) (cond [(null? l) - (let ([tags (map (lambda (k) - (format "secindex:~a:~a" (current-inexact-milliseconds) (gensym))) - keys)] - [tag (or tag (format "sec:~a:~a" (current-inexact-milliseconds) (gensym)))]) - (make-styled-part (cons tag - tags) - title - #f - (let ([l (map (lambda (k tag) - (make-index-element - #f - null - `(part ,tag) - (part-index-decl-plain-seq k) - (part-index-decl-entry-seq k))) - keys tags)]) - (if title - (cons (make-index-element - #f - null - `(part ,tag) - (list (regexp-replace #px"^(?:A|An|The)\\s" (content->string title) - "")) - (list (make-element #f title))) - l) - l)) - (make-flow (decode-accum-para accum)) - null - style))] + (let ([k-tags (map (lambda (k) + `(idx ,(make-generated-tag))) + keys)] + [tags (if (null? tags) + (list `(part ,(make-generated-tag))) + tags)]) + (make-part tag-prefix + (append tags k-tags) + title + style + (let ([l (map (lambda (k tag) + (make-index-element + #f + null + tag + (part-index-decl-plain-seq k) + (part-index-decl-entry-seq k))) + keys k-tags)]) + (append + (if title + (cons (make-index-element + #f + null + (car tags) + (list (regexp-replace #px"^(?:A|An|The)\\s" (content->string title) + "")) + (list (make-element #f title))) + l) + l) + colls)) + (make-flow (decode-accum-para accum)) + null))] [(title-decl? (car l)) (unless part-depth (error 'decode @@ -94,34 +100,35 @@ (error 'decode "found extra title: ~v" (car l))) - (loop (cdr l) next? keys accum + (loop (cdr l) next? keys colls accum (title-decl-content (car l)) - (title-decl-tag (car l)) + (title-decl-tag-prefix (car l)) + (title-decl-tags (car l)) (title-decl-style (car l)))] [(flow-element? (car l)) (let ([para (decode-accum-para accum)] - [part (decode-flow* (cdr l) keys tag style title part-depth)]) - (make-styled-part (part-tags part) - (part-title-content part) - (part-collected-info part) - (part-to-collect part) - (make-flow (append para - (list (car l)) - (flow-paragraphs (part-flow part)))) - (part-parts part) - (styled-part-style part)))] + [part (decode-flow* (cdr l) keys colls tag-prefix tags style title part-depth)]) + (make-part (part-tag-prefix part) + (part-tags part) + (part-title-content part) + (part-style part) + (part-to-collect part) + (make-flow (append para + (list (car l)) + (flow-paragraphs (part-flow part)))) + (part-parts part)))] [(part? (car l)) (let ([para (decode-accum-para accum)] - [part (decode-flow* (cdr l) keys tag style title part-depth)]) - (make-styled-part (part-tags part) - (part-title-content part) - (part-collected-info part) - (part-to-collect part) - (make-flow (append para - (flow-paragraphs - (part-flow part)))) - (cons (car l) (part-parts part)) - (styled-part-style part)))] + [part (decode-flow* (cdr l) keys colls tag-prefix tags style title part-depth)]) + (make-part (part-tag-prefix part) + (part-tags part) + (part-title-content part) + (part-style part) + (part-to-collect part) + (make-flow (append para + (flow-paragraphs + (part-flow part)))) + (cons (car l) (part-parts part))))] [(and (part-start? (car l)) (or (not part-depth) ((part-start-depth (car l)) . <= . part-depth))) @@ -138,54 +145,57 @@ (part? (car l)))) (let ([para (decode-accum-para accum)] [s (decode-styled-part (reverse s-accum) - (part-start-tag s) + (part-start-tag-prefix s) + (part-start-tags s) (part-start-style s) (part-start-title s) (add1 part-depth))] - [part (decode-flow* l keys tag style title part-depth)]) - (make-styled-part (part-tags part) - (part-title-content part) - (part-collected-info part) - (part-to-collect part) - (make-flow para) - (cons s (part-parts part)) - (styled-part-style part))) + [part (decode-flow* l keys colls tag-prefix tags style title part-depth)]) + (make-part (part-tag-prefix part) + (part-tags part) + (part-title-content part) + (part-style part) + (part-to-collect part) + (make-flow para) + (cons s (part-parts part)))) (if (splice? (car l)) (loop (append (splice-run (car l)) (cdr l)) s-accum) (loop (cdr l) (cons (car l) s-accum))))))] [(splice? (car l)) - (loop (append (splice-run (car l)) (cdr l)) next? keys accum title tag style)] - [(null? (cdr l)) (loop null #f keys (cons (car l) accum) title tag style)] + (loop (append (splice-run (car l)) (cdr l)) next? keys colls accum title tag-prefix tags style)] + [(null? (cdr l)) (loop null #f keys colls (cons (car l) accum) title tag-prefix tags style)] [(part-index-decl? (car l)) - (loop (cdr l) next? (cons (car l) keys) accum title tag style)] + (loop (cdr l) next? (cons (car l) keys) colls accum title tag-prefix tags style)] + [(part-collect-decl? (car l)) + (loop (cdr l) next? keys (cons (part-collect-decl-element (car l)) colls) accum title tag-prefix tags style)] [(and (pair? (cdr l)) (splice? (cadr l))) - (loop (cons (car l) (append (splice-run (cadr l)) (cddr l))) next? keys accum title tag style)] + (loop (cons (car l) (append (splice-run (cadr l)) (cddr l))) next? keys colls accum title tag-prefix tags style)] [(line-break? (car l)) (if next? - (loop (cdr l) #t keys accum title tag style) + (loop (cdr l) #t keys colls accum title tag-prefix tags style) (let ([m (match-newline-whitespace (cdr l))]) (if m - (let ([part (loop m #t keys null title tag style)]) - (make-styled-part (part-tags part) - (part-title-content part) - (part-collected-info part) - (part-to-collect part) - (make-flow (append (decode-accum-para accum) - (flow-paragraphs (part-flow part)))) - (part-parts part) - (styled-part-style part))) - (loop (cdr l) #f keys (cons (car l) accum) title tag style))))] - [else (loop (cdr l) #f keys (cons (car l) accum) title tag style)]))) + (let ([part (loop m #t keys colls null title tag-prefix tags style)]) + (make-part (part-tag-prefix part) + (part-tags part) + (part-title-content part) + (part-style part) + (part-to-collect part) + (make-flow (append (decode-accum-para accum) + (flow-paragraphs (part-flow part)))) + (part-parts part))) + (loop (cdr l) #f keys colls (cons (car l) accum) title tag-prefix tags style))))] + [else (loop (cdr l) #f keys colls (cons (car l) accum) title tag-prefix tags style)]))) - (define (decode-part l tag title depth) - (decode-flow* l null tag #f title depth)) + (define (decode-part l tags title depth) + (decode-flow* l null null #f tags #f title depth)) - (define (decode-styled-part l tag style title depth) - (decode-flow* l null tag style title depth)) + (define (decode-styled-part l tag-prefix tags style title depth) + (decode-flow* l null null tag-prefix tags style title depth)) (define (decode-flow l) - (part-flow (decode-flow* l null #f #f #f #f))) + (part-flow (decode-flow* l null null #f null #f #f #f))) (define (match-newline-whitespace l) (cond @@ -207,7 +217,7 @@ (loop (cdr l))))) (define (decode l) - (decode-part l #f #f 0)) + (decode-part l null #f 0)) (define (decode-paragraph l) (make-paragraph diff --git a/collects/scribble/doclang.ss b/collects/scribble/doclang.ss index 31eb64b0..61df31a4 100644 --- a/collects/scribble/doclang.ss +++ b/collects/scribble/doclang.ss @@ -43,7 +43,8 @@ (kernel-form-identifier-list #'here) (syntax->list #'(provide require - require-for-syntax))))]) + require-for-syntax + require-for-label))))]) (syntax-case expanded (begin) [(begin body1 ...) #`(doc-begin m-id exprs body1 ... . body)] @@ -53,6 +54,7 @@ (syntax->list #'(require provide require-for-syntax + require-for-label define-values define-syntaxes define-for-syntaxes)))) diff --git a/collects/scribble/html-render.ss b/collects/scribble/html-render.ss index 1e04b7b4..f4ce24eb 100644 --- a/collects/scribble/html-render.ss +++ b/collects/scribble/html-render.ss @@ -5,6 +5,8 @@ (lib "file.ss") (lib "list.ss") (lib "runtime-path.ss") + (lib "main-doc.ss" "setup") + (lib "main-collects.ss" "setup") (prefix xml: (lib "xml.ss" "xml"))) (provide render-mixin render-multi-mixin) @@ -15,12 +17,25 @@ (define current-subdirectory (make-parameter #f)) (define current-output-file (make-parameter #f)) + (define current-top-part (make-parameter #f)) (define on-separate-page (make-parameter #t)) (define next-separate-page (make-parameter #f)) (define collecting-sub (make-parameter 0)) (define current-no-links (make-parameter #f)) (define extra-breaking? (make-parameter #f)) + (define (path->relative p) + (let ([p (path->main-doc-relative p)]) + (if (path? p) + (path->main-collects-relative p) + p))) + + (define (relative->path p) + (let ([p (main-doc-relative->path p)]) + (if (path? p) + p + (main-collects-relative->path p)))) + ;; ---------------------------------------- ;; main mixin @@ -33,58 +48,57 @@ get-dest-directory format-number strip-aux - lookup quiet-table-of-contents) (define/override (get-suffix) #".html") ;; ---------------------------------------- - (define/override (collect ds fns) - (let ([ht (make-hash-table 'equal)]) - (map (lambda (d fn) - (parameterize ([current-output-file fn]) - (collect-part d #f ht null))) - ds - fns) - ht)) + (define/override (start-collect ds fns ci) + (map (lambda (d fn) + (parameterize ([current-output-file fn] + [current-top-part d]) + (collect-part d #f ci null))) + ds + fns)) - (define/public (part-whole-page? p ht) - (let ([dest (lookup p ht `(part ,(car (part-tags p))))]) + (define/public (part-whole-page? p ri) + (let ([dest (resolve-get p ri (car (part-tags p)))]) (caddr dest))) - (define/public (current-part-whole-page?) - #f) + (define/public (current-part-whole-page? d) + (eq? d (current-top-part))) - (define/override (collect-part-tags d ht number) + (define/override (collect-part-tags d ci number) (for-each (lambda (t) - (hash-table-put! ht - `(part ,t) - (list (current-output-file) - (part-title-content d) - (current-part-whole-page?)))) + (let ([key (generate-tag t ci)]) + (collect-put! ci + key + (list (path->relative (current-output-file)) + (or (part-title-content d) + '("???")) + (current-part-whole-page? d) + (format "~a" key))))) (part-tags d))) - (define/override (collect-target-element i ht) - (hash-table-put! ht - (target-element-tag i) - (list (current-output-file) - #f - (page-target-element? i)))) - + (define/override (collect-target-element i ci) + (let ([key (generate-tag (target-element-tag i) ci)]) + (collect-put! ci + key + (list (path->relative (current-output-file)) + #f + (page-target-element? i) + (format "~a" key))))) + ;; ---------------------------------------- (define/private (reveal-subparts? p) - (and (styled-part? p) - (let ([s (styled-part-style p)]) - (or (eq? s 'reveal) - (and (list? s) - (memq 'reveal s)))))) - - (define/public (render-toc-view d ht) + (part-style? p 'reveal)) + + (define/public (render-toc-view d ri) (let-values ([(top mine) (let loop ([d d][mine d]) - (let ([p (collected-info-parent (part-collected-info d))]) + (let ([p (collected-info-parent (part-collected-info d ri))]) (if p (loop p (if (reveal-subparts? d) mine @@ -95,7 +109,7 @@ (div ((class "tocviewtitle")) (a ((href "index.html") (class "tocviewlink")) - ,@(render-content (part-title-content top) d ht))) + ,@(render-content (or (part-title-content top) '("???")) d ri))) (div nbsp) (table ((class "tocviewlist") @@ -107,24 +121,24 @@ (td ((align "right")) ,@(if show-number? - (format-number (collected-info-number (part-collected-info p)) + (format-number (collected-info-number (part-collected-info p ri)) '((tt nbsp))) '("-" nbsp))) (td - (a ((href ,(let ([dest (lookup p ht `(part ,(car (part-tags p))))]) + (a ((href ,(let ([dest (resolve-get p ri (car (part-tags p)))]) (format "~a~a~a" - (from-root (car dest) + (from-root (relative->path (car dest)) (get-dest-directory)) (if (caddr dest) "" "#") (if (caddr dest) "" - `(part ,(car (part-tags p))))))) + (cadddr dest))))) (class ,(if (eq? p mine) "tocviewselflink" "tocviewlink"))) - ,@(render-content (part-title-content p) d ht)))))) + ,@(render-content (or (part-title-content p) '("???")) d ri)))))) (let loop ([l (map (lambda (v) (cons v #t)) (part-parts top))]) (cond [(null? l) null] @@ -133,92 +147,101 @@ (part-parts (caar l))) (cdr l))))] [else (cons (car l) (loop (cdr l)))]))))) - ,@(if (ormap (lambda (p) (part-whole-page? p ht)) (part-parts d)) - null - (let ([ps (cdr - (let flatten ([d d]) - (cons d - (apply - append - (letrec ([flow-targets - (lambda (flow) - (apply append (map flow-element-targets (flow-paragraphs flow))))] - [flow-element-targets - (lambda (e) - (cond - [(table? e) (table-targets e)] - [(paragraph? e) (para-targets e)] - [(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) - null]))] - [para-targets - (lambda (para) - (let loop ([c (paragraph-content para)]) - (cond - [(empty? c) null] - [else (let ([a (car c)]) - (cond - [(toc-target-element? a) - (cons a (loop (cdr c)))] - [(element? a) - (append (loop (element-content a)) - (loop (cdr c)))] - [(delayed-element? a) - (loop (cons (force-delayed-element a this d ht) - (cdr c)))] - [else - (loop (cdr c))]))])))] - [table-targets - (lambda (table) - (apply append - (map (lambda (flows) - (apply append (map (lambda (f) - (if (eq? f 'cont) - null - (flow-targets f))) - flows))) - (table-flowss table))))]) - (apply append (map flow-element-targets (flow-paragraphs (part-flow d))))) - (map flatten (part-parts d))))))]) - (if (null? ps) - null - `((div ((class "tocsub")) - (div ((class "tocsubtitle")) - "On this page:") - (table - ((class "tocsublist") - (cellspacing "0")) - ,@(map (lambda (p) - (parameterize ([current-no-links #t] - [extra-breaking? #t]) - `(tr - (td - ,@(if (part? p) - `((span ((class "tocsublinknumber")) - ,@(format-number (collected-info-number (part-collected-info p)) - '((tt nbsp))))) - '("")) - (a ((href ,(if (part? p) - (let ([dest (lookup p ht `(part ,(car (part-tags p))))]) - (format "#~a" - `(part ,(car (part-tags p))))) - (format "#~a" (target-element-tag p)))) - (class ,(if (part? p) - "tocsubseclink" - "tocsublink"))) - ,@(if (part? p) - (render-content (part-title-content p) d ht) - (render-content (element-content p) d ht))))))) - ps))))))) + ,@(render-onthispage-contents d ri top) ,@(apply append (map (lambda (t) - (render-table t d ht)) + (render-table t d ri)) (filter auxiliary-table? (flow-paragraphs (part-flow d))))))))) - (define/public (render-one-part d ht fn number) + (define/private (render-onthispage-contents d ri top) + (if (ormap (lambda (p) (part-whole-page? p ri)) + (part-parts d)) + null + (let* ([nearly-top? (lambda (d) + (eq? top (collected-info-parent (part-collected-info d ri))))] + [ps ((if (nearly-top? d) values cdr) + (let flatten ([d d]) + (apply + append + ;; don't include the section if it's in the TOC + (if (nearly-top? d) + null + (list d)) + ;; get internal targets: + (letrec ([flow-targets + (lambda (flow) + (apply append (map flow-element-targets (flow-paragraphs flow))))] + [flow-element-targets + (lambda (e) + (cond + [(table? e) (table-targets e)] + [(paragraph? e) (para-targets e)] + [(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) + null]))] + [para-targets + (lambda (para) + (let loop ([c (paragraph-content para)]) + (cond + [(empty? c) null] + [else (let ([a (car c)]) + (cond + [(toc-target-element? a) + (cons a (loop (cdr c)))] + [(element? a) + (append (loop (element-content a)) + (loop (cdr c)))] + [(delayed-element? a) + (loop (cons (delayed-element-content a ri) + (cdr c)))] + [else + (loop (cdr c))]))])))] + [table-targets + (lambda (table) + (apply append + (map (lambda (flows) + (apply append (map (lambda (f) + (if (eq? f 'cont) + null + (flow-targets f))) + flows))) + (table-flowss table))))]) + (apply append (map flow-element-targets (flow-paragraphs (part-flow d))))) + (map flatten (part-parts d)))))]) + (if (null? ps) + null + `((div ((class "tocsub")) + (div ((class "tocsubtitle")) + "On this page:") + (table + ((class "tocsublist") + (cellspacing "0")) + ,@(map (lambda (p) + (parameterize ([current-no-links #t] + [extra-breaking? #t]) + `(tr + (td + ,@(if (part? p) + `((span ((class "tocsublinknumber")) + ,@(format-number (collected-info-number + (part-collected-info p ri)) + '((tt nbsp))))) + '("")) + (a ((href ,(if (part? p) + (format "#~a" (tag-key (car (part-tags p)) ri)) + (format "#~a" (tag-key (target-element-tag p) ri)))) + (class ,(if (part? p) + "tocsubseclink" + "tocsublink"))) + ,@(if (part? p) + (render-content (or (part-title-content p) '("???")) d ri) + (render-content (element-content p) d ri))))))) + ps)))))))) + + (define/public (render-one-part d ri fn number) (parameterize ([current-output-file fn]) (let ([xpr `(html () (head @@ -226,32 +249,28 @@ (content "text-html; charset=utf-8"))) ,@(let ([c (part-title-content d)]) (if c - `((title ,@(format-number number '(nbsp)) ,(content->string c this d ht))) + `((title ,@(format-number number '(nbsp)) ,(content->string c this d ri))) null)) (link ((rel "stylesheet") (type "text/css") (href "scribble.css") (title "default")))) - (body ,@(render-toc-view d ht) - (div ((class "main")) ,@(render-part d ht))))]) + (body ,@(render-toc-view d ri) + (div ((class "main")) ,@(render-part d ri))))]) (install-file scribble-css) (xml:write-xml/content (xml:xexpr->xml xpr))))) - (define/override (render-one d ht fn) - (render-one-part d ht fn null)) + (define/override (render-one d ri fn) + (render-one-part d ri fn null)) - (define/override (render-part d ht) - (let ([number (collected-info-number (part-collected-info d))]) + (define/override (render-part d ri) + (let ([number (collected-info-number (part-collected-info d ri))]) `(,@(if (and (not (part-title-content d)) (null? number)) null - (if (and (styled-part? d) - (let ([s (styled-part-style d)]) - (or (eq? s 'hidden) - (and (list? s) - (memq 'hidden s))))) + (if (part-style? d 'hidden) (map (lambda (t) - `(a ((name ,(format "~a" `(part ,t)))))) + `(a ((name ,(format "~a" (tag-key t ri)))))) (part-tags d)) `((,(case (length number) [(0) 'h2] @@ -260,21 +279,21 @@ [else 'h5]) ,@(format-number number '((tt nbsp))) ,@(map (lambda (t) - `(a ((name ,(format "~a" `(part ,t)))))) + `(a ((name ,(format "~a" (tag-key t ri)))))) (part-tags d)) ,@(if (part-title-content d) - (render-content (part-title-content d) d ht) + (render-content (part-title-content d) d ri) null))))) - ,@(render-flow* (part-flow d) d ht #f) + ,@(render-flow* (part-flow d) d ri #f) ,@(let loop ([pos 1] [secs (part-parts d)]) (if (null? secs) null (append - (render-part (car secs) ht) + (render-part (car secs) ri) (loop (add1 pos) (cdr secs)))))))) - (define/private (render-flow* p part ht special-last?) + (define/private (render-flow* p part ri special-last?) ;; Wrap each table with
, except for a trailing table
;; when `special-last?' is #t
(let loop ([f (flow-paragraphs p)])
@@ -283,71 +302,78 @@
[(and (table? (car f))
(or (not special-last?)
(not (null? (cdr f)))))
- (cons `(p ,@(render-flow-element (car f) part ht))
+ (cons `(p ,@(render-flow-element (car f) part ri))
(loop (cdr f)))]
[else
- (append (render-flow-element (car f) part ht)
+ (append (render-flow-element (car f) part ri)
(loop (cdr f)))])))
- (define/override (render-flow p part ht)
- (render-flow* p part ht #t))
+ (define/override (render-flow p part ri)
+ (render-flow* p part ri #t))
- (define/override (render-paragraph p part ht)
+ (define/override (render-paragraph p part ri)
`((p ,@(if (styled-paragraph? p)
`(((class ,(styled-paragraph-style p))))
null)
- ,@(super render-paragraph p part ht))))
+ ,@(super render-paragraph p part ri))))
- (define/override (render-element e part ht)
+ (define/override (render-element e part ri)
(cond
+ [(hover-element? e)
+ `((span ((title ,(hover-element-text e))) ,@(render-plain-element e part ri)))]
[(target-element? e)
- `((a ((name ,(target-element-tag e))))
- ,@(render-plain-element e part ht))]
+ `((a ((name ,(format "~a" (tag-key (target-element-tag e) ri)))))
+ ,@(render-plain-element e part ri))]
[(and (link-element? e)
(not (current-no-links)))
(parameterize ([current-no-links #t])
- (let ([dest (lookup part ht (link-element-tag e))])
+ (let ([dest (resolve-get part ri (link-element-tag e))])
(if dest
`((a ((href ,(format "~a~a~a"
- (from-root (car dest)
+ (from-root (relative->path (car dest))
(get-dest-directory))
(if (caddr dest)
""
"#")
(if (caddr dest)
""
- (link-element-tag e))))
+ (cadddr dest))))
,@(if (string? (element-style e))
`((class ,(element-style e)))
null))
,@(if (null? (element-content e))
- (render-content (strip-aux (cadr dest)) part ht)
- (render-content (element-content e) part ht))))
- (begin (fprintf (current-error-port) "Undefined link: ~s~n" (link-element-tag e)) ; XXX Add source info
- `((font ((class "badlink"))
- ,@(if (null? (element-content e))
- `(,(format "~s" (link-element-tag e)))
- (render-plain-element e part ht))))))))]
- [else (render-plain-element e part ht)]))
+ (render-content (strip-aux (cadr dest)) part ri)
+ (render-content (element-content e) part ri))))
+ (begin
+ (when #f
+ (fprintf (current-error-port)
+ "Undefined link: ~s~n"
+ (tag-key (link-element-tag e) ri)))
+ `((font ((class "badlink"))
+ ,@(if (null? (element-content e))
+ `(,(format "~s" (tag-key (link-element-tag e) ri)))
+ (render-plain-element e part ri))))))))]
+ [else (render-plain-element e part ri)]))
- (define/private (render-plain-element e part ht)
+ (define/private (render-plain-element e part ri)
(let ([style (and (element? e)
(element-style e))])
(cond
[(symbol? style)
(case style
- [(italic) `((i ,@(super render-element e part ht)))]
- [(bold) `((b ,@(super render-element e part ht)))]
- [(tt) `((tt ,@(super render-element e part ht)))]
- [(sf) `((b (font ([size "-1"][face "Helvetica"]) ,@(super render-element e part ht))))]
- [(subscript) `((sub ,@(super render-element e part ht)))]
- [(superscript) `((sup ,@(super render-element e part ht)))]
+ [(italic) `((i ,@(super render-element e part ri)))]
+ [(bold) `((b ,@(super render-element e part ri)))]
+ [(tt) `((tt ,@(super render-element e part ri)))]
+ [(no-break) `((span ([class "nobreak"]) ,@(super render-element e part ri)))]
+ [(sf) `((b (font ([size "-1"][face "Helvetica"]) ,@(super render-element e part ri))))]
+ [(subscript) `((sub ,@(super render-element e part ri)))]
+ [(superscript) `((sup ,@(super render-element e part ri)))]
[(hspace) `((span ([class "hspace"])
,@(let ([str (content->string (element-content e))])
(map (lambda (c) 'nbsp) (string->list str)))))]
[else (error 'html-render "unrecognized style symbol: ~e" style)])]
[(string? style)
- `((span ([class ,style]) ,@(super render-element e part ht)))]
+ `((span ([class ,style]) ,@(super render-element e part ri)))]
[(and (pair? style)
(eq? (car style) 'show-color))
`((font ((style ,(format "background-color: ~a"
@@ -357,16 +383,16 @@
(cdr style))))))
(tt nbsp nbsp nbsp nbsp nbsp))
nbsp
- ,@(super render-element e part ht))]
+ ,@(super render-element e part ri))]
[(target-url? style)
(if (current-no-links)
- (super render-element e part ht)
+ (super render-element e part ri)
(parameterize ([current-no-links #t])
- `((a ((href ,(target-url-addr style))) ,@(super render-element e part ht)))))]
+ `((a ((href ,(target-url-addr style))) ,@(super render-element e part ri)))))]
[(image-file? style) `((img ((src ,(install-file (image-file-path style))))))]
- [else (super render-element e part ht)])))
+ [else (super render-element e part ri)])))
- (define/override (render-table t part ht)
+ (define/override (render-table t part ri)
`((table ((cellspacing "0")
,@(case (table-style t)
[(boxed) '((class "boxed"))]
@@ -423,36 +449,36 @@
[(eq? 'cont (car ds)) (loop (+ n 1) (cdr ds))]
[else n])))))
null))
- ,@(render-flow d part ht))
+ ,@(render-flow d part ri))
(loop (cdr ds) (cdr as) (cdr vas)))))))))
(table-flowss t)
(cdr (or (and (list? (table-style t))
(assoc 'row-styles (or (table-style t) null)))
(cons #f (map (lambda (x) #f) (table-flowss t)))))))))
- (define/override (render-blockquote t part ht)
+ (define/override (render-blockquote t part ri)
`((blockquote ,@(if (string? (blockquote-style t))
`(((class ,(blockquote-style t))))
null)
,@(apply append
(map (lambda (i)
- (render-flow-element i part ht))
+ (render-flow-element i part ri))
(blockquote-paragraphs t))))))
- (define/override (render-itemization t part ht)
+ (define/override (render-itemization t part ri)
`((ul
,@(map (lambda (flow)
- `(li ,@(render-flow flow part ht)))
+ `(li ,@(render-flow flow part ri)))
(itemization-flows t)))))
- (define/override (render-other i part ht)
+ (define/override (render-other i part ri)
(cond
[(string? i) (let ([m (and (extra-breaking?)
(regexp-match-positions #rx":" i))])
(if m
(list* (substring i 0 (cdar m))
`(span ((class "mywbr")) " ")
- (render-other (substring i (cdar m)) part ht))
+ (render-other (substring i (cdar m)) part ri))
(list i)))]
[(eq? i 'mdash) `(" " ndash " ")]
[(eq? i 'hline) `((hr))]
@@ -470,7 +496,9 @@
(class %
(inherit render-one
render-one-part
- render-content)
+ render-content
+ part-whole-page?
+ format-number)
(define/override (get-suffix) #"")
@@ -479,10 +507,16 @@
(current-subdirectory))
(super get-dest-directory)))
- (define/private (derive-filename d ht)
+ (define/private (derive-filename d)
(let ([fn (format "~a.html" (regexp-replace*
"[^-a-zA-Z0-9_=]"
- (format "~a" (car (part-tags d)))
+ (let ([s (cadr (car (part-tags d)))])
+ (if (string? s)
+ s
+ (if (part-title-content d)
+ (content->string (part-title-content d))
+ ;; last-ditch effort to make up a unique name:
+ (format "???~a" (eq-hash-code d)))))
"_"))])
(when ((string-length fn) . >= . 48)
(error "file name too long (need a tag):" fn))
@@ -493,28 +527,25 @@
(build-path fn "index.html"))
fns)))
- (define/override (current-part-whole-page?)
+ (define/override (current-part-whole-page? d)
((collecting-sub) . <= . 2))
(define/private (toc-part? d)
- (and (styled-part? d)
- (let ([st (styled-part-style d)])
- (or (eq? 'toc st)
- (and (list? st) (memq 'toc st))))))
+ (part-style? d 'toc))
- (define/override (collect-part d parent ht number)
+ (define/override (collect-part d parent ci number)
(let ([prev-sub (collecting-sub)])
(parameterize ([collecting-sub (if (toc-part? d)
1
(add1 prev-sub))])
(if (= 1 prev-sub)
- (let ([filename (derive-filename d ht)])
+ (let ([filename (derive-filename d)])
(parameterize ([current-output-file (build-path (path-only (current-output-file))
filename)])
- (super collect-part d parent ht number)))
- (super collect-part d parent ht number)))))
+ (super collect-part d parent ci number)))
+ (super collect-part d parent ci number)))))
- (define/override (render ds fns ht)
+ (define/override (render ds fns ri)
(map (lambda (d fn)
(printf " [Output to ~a/index.html]\n" fn)
(unless (directory-exists? fn)
@@ -523,7 +554,7 @@
(let ([fn (build-path fn "index.html")])
(with-output-to-file fn
(lambda ()
- (render-one d ht fn))
+ (render-one d ri fn))
'truncate/replace))))
ds
fns))
@@ -538,8 +569,8 @@
(inherit render-table)
- (define/private (find-siblings d)
- (let ([parent (collected-info-parent (part-collected-info d))])
+ (define/private (find-siblings d ri)
+ (let ([parent (collected-info-parent (part-collected-info d ri))])
(let loop ([l (if parent
(part-parts parent)
(if (null? (part-parts d))
@@ -552,12 +583,12 @@
(cadr l)))]
[else (loop (cdr l) (car l))]))))
- (define/private (part-parent d)
- (collected-info-parent (part-collected-info d)))
+ (define/private (part-parent d ri)
+ (collected-info-parent (part-collected-info d ri)))
- (define/private (navigation d ht)
- (let ([parent (part-parent d)])
- (let*-values ([(prev next) (find-siblings d)]
+ (define/private (navigation d ri)
+ (let ([parent (part-parent d ri)])
+ (let*-values ([(prev next) (find-siblings d ri)]
[(prev) (if prev
(let loop ([prev prev])
(if (and (toc-part? prev)
@@ -575,17 +606,17 @@
parent
(toc-part? parent))
(let-values ([(prev next)
- (find-siblings parent)])
+ (find-siblings parent ri)])
next)]
[else next])]
[(index) (let loop ([d d])
- (let ([p (part-parent d)])
+ (let ([p (part-parent d ri)])
(if p
(loop p)
(let ([subs (part-parts d)])
(and (pair? subs)
(let ([d (car (last-pair subs))])
- (and (equal? '("Index") (part-title-content d))
+ (and (part-style? d 'index)
d)))))))])
`(,@(render-table (make-table
'at-left
@@ -614,9 +645,9 @@
(make-link-element
#f
index-content
- `(part ,(car (part-tags index))))))))))
+ (car (part-tags index)))))))))
null))))
- d ht)
+ d ri)
,@(render-table (make-table
'at-right
(list
@@ -628,7 +659,7 @@
(make-element
(if parent
(make-target-url (if prev
- (derive-filename prev ht)
+ (derive-filename prev)
"index.html"))
"nonavigation")
prev-content)
@@ -637,34 +668,34 @@
(if parent
(make-target-url
(if (toc-part? parent)
- (derive-filename parent ht)
+ (derive-filename parent)
"index.html"))
"nonavigation")
up-content)
sep-element
(make-element
(if next
- (make-target-url (derive-filename next ht))
+ (make-target-url (derive-filename next))
"nonavigation")
next-content))))))))
d
- ht)))))
+ ri)))))
- (define/override (render-part d ht)
- (let ([number (collected-info-number (part-collected-info d))])
+ (define/override (render-part d ri)
+ (let ([number (collected-info-number (part-collected-info d ri))])
(cond
[(and (not (on-separate-page))
(or (= 1 (length number))
(next-separate-page)))
;; Render as just a link, and put the actual
;; content in a new file:
- (let* ([filename (derive-filename d ht)]
+ (let* ([filename (derive-filename d)]
[full-path (build-path (path-only (current-output-file))
filename)])
(parameterize ([on-separate-page #t])
(with-output-to-file full-path
(lambda ()
- (render-one-part d ht full-path number))
+ (render-one-part d ri full-path number))
'truncate/replace)
null))]
[else
@@ -673,14 +704,14 @@
[on-separate-page #f])
(if sep?
;; Navigation bars;
- `(,@(navigation d ht)
+ `(,@(navigation d ri)
(p nbsp)
- ,@(super render-part d ht)
+ ,@(super render-part d ri)
(p nbsp)
- ,@(navigation d ht)
+ ,@(navigation d ri)
(p nbsp))
;; Normal section render
- (super render-part d ht))))])))
+ (super render-part d ri))))])))
(super-new)))
diff --git a/collects/scribble/latex-render.ss b/collects/scribble/latex-render.ss
index c439a1b3..57dcc9bc 100644
--- a/collects/scribble/latex-render.ss
+++ b/collects/scribble/latex-render.ss
@@ -18,13 +18,12 @@
render-flow-element
render-content
install-file
- format-number
- lookup)
+ format-number)
(define (define-color s s2)
(printf "\\newcommand{\\~a}[1]{{\\mytexttt{\\color{~a}{#1}}}}\n" s s2))
- (define/override (render-one d ht fn)
+ (define/override (render-one d ri fn)
(printf "\\documentclass{article}\n")
(printf "\\parskip=10pt%\n")
(printf "\\parindent=0pt%\n")
@@ -75,17 +74,16 @@
(printf "\\begin{document}\n\\sloppy\n")
(when (part-title-content d)
(printf "\\title{")
- (render-content (part-title-content d) d ht)
+ (render-content (part-title-content d) d ri)
(printf "}\\maketitle\n"))
- (render-part d ht)
+ (render-part d ri)
(printf "\\end{document}\n"))
- (define/override (render-part d ht)
- (let ([number (collected-info-number (part-collected-info d))])
+ (define/override (render-part d ri)
+ (let ([number (collected-info-number (part-collected-info d ri))])
(when (and (part-title-content d)
(pair? number))
- (when (and (styled-part? d)
- (eq? 'index (styled-part-style d)))
+ (when (part-style? d 'index)
(printf "\\twocolumn\n\\parskip=0pt\n\\addcontentsline{toc}{section}{Index}\n"))
(printf "\\~a~a{"
(case (length number)
@@ -97,20 +95,19 @@
(not (car number)))
"*"
""))
- (render-content (part-title-content d) d ht)
+ (render-content (part-title-content d) d ri)
(printf "}")
- (when (and (styled-part? d)
- (eq? 'index (styled-part-style d)))
+ (when (part-style? d 'index)
(printf "\n\n")))
(for-each (lambda (t)
- (printf "\\label{t:~a}" (t-encode `(part ,t))))
+ (printf "\\label{t:~a}" (t-encode (tag-key t ri))))
(part-tags d))
- (render-flow (part-flow d) d ht)
- (for-each (lambda (sec) (render-part sec ht))
+ (render-flow (part-flow d) d ri)
+ (for-each (lambda (sec) (render-part sec ri))
(part-parts d))
null))
- (define/override (render-paragraph p part ht)
+ (define/override (render-paragraph p part ri)
(printf "\n\n")
(let ([margin? (and (styled-paragraph? p)
(equal? "refpara" (styled-paragraph-style p)))])
@@ -118,28 +115,35 @@
(printf "\\marginpar{\\footnotesize "))
(if (toc-paragraph? p)
(printf "\\newpage \\tableofcontents \\newpage")
- (super render-paragraph p part ht))
+ (super render-paragraph p part ri))
(when margin?
(printf "}")))
(printf "\n\n")
null)
- (define/override (render-element e part ht)
+ (define/override (render-element e part ri)
(let ([part-label? (and (link-element? e)
(pair? (link-element-tag e))
(eq? 'part (car (link-element-tag e)))
(null? (element-content e)))])
(parameterize ([show-link-page-numbers #f])
(when (target-element? e)
- (printf "\\label{t:~a}" (t-encode (target-element-tag e))))
+ (printf "\\label{t:~a}" (t-encode (tag-key (target-element-tag e) ri))))
(when part-label?
(printf "\\S")
- (render-content (let ([dest (lookup part ht (link-element-tag e))])
+ (render-content (let ([dest (resolve-get part ri (link-element-tag e))])
(if dest
- (format-number (cadr dest) null)
+ (if (list? (cadr dest))
+ (format-number (cadr dest) null)
+ (begin
+ (fprintf (current-error-port)
+ "Internal tag error: ~s -> ~s\n"
+ (link-element-tag e)
+ dest)
+ '("!!!")))
(list "???")))
part
- ht)
+ ri)
(printf " ``"))
(let ([style (and (element? e)
(element-style e))]
@@ -147,7 +151,7 @@
(printf "{\\~a{" s)
(parameterize ([rendering-tt (or tt?
(rendering-tt))])
- (super render-element e part ht))
+ (super render-element e part ri))
(printf "}}"))])
(cond
[(symbol? style)
@@ -155,6 +159,7 @@
[(italic) (wrap e "textit" #f)]
[(bold) (wrap e "textbf" #f)]
[(tt) (wrap e "mytexttt" #t)]
+ [(nobreak) (super render-element e part ri)]
[(sf) (wrap e "textsf" #f)]
[(subscript) (wrap e "textsub" #f)]
[(superscript) (wrap e "textsuper" #f)]
@@ -170,12 +175,12 @@
[(image-file? style)
(let ([fn (install-file (image-file-path style))])
(printf "\\includegraphics{~a}" fn))]
- [else (super render-element e part ht)])))
+ [else (super render-element e part ri)])))
(when part-label?
(printf "''"))
(when (and (link-element? e)
(show-link-page-numbers))
- (printf ", \\pageref{t:~a}" (t-encode (link-element-tag e))))
+ (printf ", \\pageref{t:~a}" (t-encode (tag-key (link-element-tag e) ri))))
null))
(define/private (t-encode s)
@@ -192,7 +197,7 @@
(format "x~x" (char->integer c))]))
(string->list (format "~s" s)))))
- (define/override (render-table t part ht)
+ (define/override (render-table t part ri)
(let* ([boxed? (eq? 'boxed (table-style t))]
[index? (eq? 'index (table-style t))]
[inline? (and (not boxed?)
@@ -262,7 +267,7 @@
[else n]))])
(unless (= cnt 1)
(printf "\\multicolumn{~a}{l}{" cnt))
- (render-flow (car flows) part ht)
+ (render-flow (car flows) part ri)
(unless (= cnt 1)
(printf "}"))
(unless (null? (list-tail flows cnt))
@@ -284,25 +289,25 @@
""))))))
null)
- (define/override (render-itemization t part ht)
+ (define/override (render-itemization t part ri)
(printf "\n\n\\begin{itemize}\n")
(for-each (lambda (flow)
(printf "\n\n\\item ")
- (render-flow flow part ht))
+ (render-flow flow part ri))
(itemization-flows t))
(printf "\n\n\\end{itemize}\n")
null)
- (define/override (render-blockquote t part ht)
+ (define/override (render-blockquote t part ri)
(printf "\n\n\\begin{quote}\n")
(parameterize ([current-table-mode (list "blockquote" t)])
(for-each (lambda (e)
- (render-flow-element e part ht))
+ (render-flow-element e part ri))
(blockquote-paragraphs t)))
(printf "\n\n\\end{quote}\n")
null)
- (define/override (render-other i part ht)
+ (define/override (render-other i part ri)
(cond
[(string? i) (display-protected i)]
[(symbol? i) (display
@@ -362,11 +367,11 @@
;; ----------------------------------------
- (define/override (table-of-contents sec ht)
+ (define/override (table-of-contents sec ri)
;; FIXME: isn't local to the section
(make-toc-paragraph null))
- (define/override (local-table-of-contents part ht)
+ (define/override (local-table-of-contents part ri)
(make-paragraph null))
;; ----------------------------------------
diff --git a/collects/scribble/manual.ss b/collects/scribble/manual.ss
index 2833ca2b..29e17708 100644
--- a/collects/scribble/manual.ss
+++ b/collects/scribble/manual.ss
@@ -10,6 +10,8 @@
(lib "class.ss")
(lib "stxparam.ss"))
(require-for-syntax (lib "stxparam.ss"))
+ (require-for-label (lib "lang.ss" "big")
+ (lib "class.ss"))
(provide (all-from "basic.ss"))
@@ -50,10 +52,24 @@
(define (to-element/id s)
(make-element "schemesymbol" (list (to-element/no-color s))))
- (define (keep-s-expr ctx s v)
+ (define-syntax (keep-s-expr stx)
+ (syntax-case stx ()
+ [(_ ctx s srcloc)
+ (let ([sv (syntax-e #'s)])
+ (if (or (number? sv)
+ (boolean? sv)
+ (and (pair? sv)
+ (identifier? (car sv))
+ (module-identifier=? #'cons (car sv))))
+ ;; We know that the context is irrelvant
+ #'s
+ ;; Context may be relevant:
+ #'(*keep-s-expr s ctx)))]))
+ (define (*keep-s-expr s ctx)
(if (symbol? s)
(make-just-context s ctx)
s))
+
(define (add-sq-prop s name val)
(if (eq? name 'paren-shape)
(make-shaped-parens s val)
@@ -158,9 +174,9 @@
(define (exec . str)
(make-element 'tt (decode-content str)))
(define (Flag . str)
- (make-element 'tt (cons "-" (decode-content str))))
+ (make-element 'no-break (list (make-element 'tt (cons "-" (decode-content str))))))
(define (DFlag . str)
- (make-element 'tt (cons "--" (decode-content str))))
+ (make-element 'no-break (list (make-element 'tt (cons "--" (decode-content str))))))
(define (envvar . str)
(make-element 'tt (decode-content str)))
(define (indexed-envvar . str)
@@ -198,9 +214,8 @@
(elem (method a b) " in " (scheme a))]))
(define (*method sym id)
- (let ([tag (format "~a::~a"
- (register-scheme-definition id)
- sym)])
+ (let ([tag (method-tag (register-scheme-definition id #t)
+ sym)])
(make-element
"schemesymbol"
(list (make-link-element
@@ -208,6 +223,9 @@
(list (symbol->string sym))
tag)))))
+ (define (method-tag vtag sym)
+ (list 'meth
+ (format "~a::~a" (cadr vtag) sym)))
;; ----------------------------------------
@@ -222,7 +240,7 @@
(provide deftech tech techlink)
- (define (*tech make-elem style s)
+ (define (*tech make-elem style doc s)
(let* ([c (decode-content s)]
[s (regexp-replace* #px"[-\\s]+"
(regexp-replace
@@ -235,26 +253,27 @@
" ")])
(make-elem style
c
- (format "tech-term:~a" s))))
+ (list 'tech (doc-prefix doc s)))))
(define (deftech . s)
(let* ([e (apply defterm s)]
- [t (*tech make-target-element #f (list e))])
+ [t (*tech make-target-element #f #f (list e))])
(make-index-element #f
(list t)
(target-element-tag t)
(list (element->string e))
(list e))))
- (define (tech . s)
- (*tech make-link-element "techlink" s))
+ (define (tech #:doc [doc #f] . s)
+ (*tech make-link-element "techlink" doc s))
- (define (techlink . s)
- (*tech make-link-element #f s))
+ (define (techlink #:doc [doc #f] . s)
+ (*tech make-link-element #f doc s))
;; ----------------------------------------
- (provide defproc defproc* defstruct defthing defparam defboolparam
+ (provide declare-exporting
+ defproc defproc* defstruct defthing defparam defboolparam
defform defform* defform/subs defform*/subs defform/none
defidform
specform specform/subs
@@ -262,6 +281,33 @@
schemegrammar schemegrammar*
var svar void-const undefined-const)
+ (define-syntax declare-exporting
+ (syntax-rules ()
+ [(_ lib ...) (*declare-exporting '(lib ...))]))
+
+ (define (*declare-exporting libs)
+ (make-part-collect-decl
+ (make-collect-element #f
+ null
+ (lambda (ri)
+ (collect-put! ri '(exporting-libraries #f)libs)))))
+
+ (define-syntax (quote-syntax/loc stx)
+ (syntax-case stx ()
+ [(_ id)
+ (with-syntax ([loc
+ (let ([s #'id])
+ (list (syntax-source s)
+ (syntax-line s)
+ (syntax-column s)
+ (syntax-position s)
+ (syntax-span s)))])
+ #'(let ([s (quote-syntax id)])
+ (datum->syntax-object s
+ (syntax-e s)
+ 'loc
+ s)))]))
+
(define void-const
(schemeresultfont "#