more scribble rendering and doc details

svn: r9261
This commit is contained in:
Matthew Flatt 2008-04-11 19:09:26 +00:00
parent d54d301db3
commit b9d7824c8e
8 changed files with 77 additions and 54 deletions

View File

@ -4,16 +4,17 @@
(provide (rename-out [*read read]
[*read-syntax read-syntax]))
(define (*read in)
(wrap in read))
(define (*read in modpath line col pos)
(wrap in read modpath #f line col pos))
(define (*read-syntax src in)
(define (*read-syntax src in modpath line col pos)
(wrap in (lambda (in)
(read-syntax src in))))
(read-syntax src in))
modpath src line col pos))
(define (wrap port read)
(define (wrap port read modpath src line col pos)
(parameterize ([read-case-sensitive #f]
[read-accept-infix-dot #f]
[read-curly-brace-as-paren #f]
[read-square-bracket-as-paren #f])
(wrap-read-all 'r5rs port read))))
(wrap-read-all 'r5rs port read modpath src line col pos))))

View File

@ -105,7 +105,7 @@
(let-values ([(file anchor) (xref-tag->path+anchor xref t)])
(printf "Sending to web browser...\n file: ~a\n" file)
(when anchor (printf " anchor: ~a\n" anchor))
(unless (send-url/file file #:fragment (uri-encode anchor))
(unless (send-url/file file #:fragment (and anchor (uri-encode anchor)))
(error 'help "browser launch failed"))))
(define generate-search-results #f)

View File

@ -13,7 +13,8 @@
(define render%
(class object%
(init-field dest-dir)
(init-field dest-dir
[refer-to-existing-files #f])
(define/public (get-dest-directory) dest-dir)
@ -370,29 +371,33 @@
;; ----------------------------------------
(define/public (install-file fn)
(let ([src-dir (path-only fn)]
[dest-dir (get-dest-directory)]
[fn (file-name-from-path fn)])
(let ([src-file (build-path (or src-dir (current-directory)) fn)]
[dest-file (build-path (or dest-dir (current-directory)) fn)])
(unless (and (file-exists? dest-file)
(call-with-input-file*
src-file
(lambda (src)
(call-with-input-file*
dest-file
(lambda (dest)
(or (equal? (port-file-identity src)
(port-file-identity dest))
(let loop ()
(let ([s (read-bytes 4096 src)]
[d (read-bytes 4096 dest)])
(and (equal? s d)
(or (eof-object? s) (loop)))))))))))
(when (file-exists? dest-file) (delete-file dest-file))
(make-directory* (path-only dest-file))
(copy-file src-file dest-file))
(path->string fn))))
(if refer-to-existing-files
(if (string? fn)
(string->path fn)
fn)
(let ([src-dir (path-only fn)]
[dest-dir (get-dest-directory)]
[fn (file-name-from-path fn)])
(let ([src-file (build-path (or src-dir (current-directory)) fn)]
[dest-file (build-path (or dest-dir (current-directory)) fn)])
(unless (and (file-exists? dest-file)
(call-with-input-file*
src-file
(lambda (src)
(call-with-input-file*
dest-file
(lambda (dest)
(or (equal? (port-file-identity src)
(port-file-identity dest))
(let loop ()
(let ([s (read-bytes 4096 src)]
[d (read-bytes 4096 dest)])
(and (equal? s d)
(or (eof-object? s) (loop)))))))))))
(when (file-exists? dest-file) (delete-file dest-file))
(make-directory* (path-only dest-file))
(copy-file src-file dest-file))
(path->string fn)))))
;; ----------------------------------------

View File

@ -777,7 +777,11 @@
`((width ,(to-num w))
(height ,(to-num h))))
null))))])
`((img ((src ,(install-file src))) ,@sz)))]
`((img ((src ,(let ([p (install-file src)])
(if (path? p)
(url->string (path->url p))
p))))
,@sz)))]
[else (super render-element e part ri)])))
(define/override (render-table t part ri need-inline?)

View File

@ -1850,7 +1850,11 @@
(provide commandline)
(define (commandline . s)
(make-paragraph (list (hspace 2) (apply tt s))))
(make-paragraph (cons (hspace 2) (map (lambda (s)
(if (string? s)
(make-element 'tt (list s))
s))
s))))
(define (elemtag t . body)
(make-target-element #f (decode-content body) `(elem ,t)))

View File

@ -63,20 +63,20 @@
;; dest-file can be #f, which will make it return a string holding the
;; resulting html
(define (xref-render xrefs doc dest-file
#:render% [render% (html:render-mixin render%)])
;; In case rendering writes a file (like an image file), which to the
;; temp directory:
(parameterize ([current-directory (find-system-path 'temp-dir)])
(let* ([dest-file (if (string? dest-file) (string->path dest-file) dest-file)]
[renderer (new render% [dest-dir (and dest-file (path-only dest-file))]
[css-path 'inline])]
[ci (send renderer collect (list doc) (list dest-file))]
[_ (send renderer transfer-info ci (resolve-info-ci (xrefs-ri xrefs)))]
[ri (send renderer resolve (list doc) (list dest-file) ci)]
[xs (send renderer render (list doc) (list dest-file) ri)])
(if dest-file
(void)
(car xs)))))
#:render% [render% (html:render-mixin render%)]
#:refer-to-existing-files? [use-existing? (not dest-file)])
(let* ([dest-file (if (string? dest-file) (string->path dest-file) dest-file)]
[renderer (new render%
[dest-dir (and dest-file (path-only dest-file))]
[refer-to-existing-files use-existing?]
[css-path 'inline])]
[ci (send renderer collect (list doc) (list dest-file))]
[_ (send renderer transfer-info ci (resolve-info-ci (xrefs-ri xrefs)))]
[ri (send renderer resolve (list doc) (list dest-file) ci)]
[xs (send renderer render (list doc) (list dest-file) ri)])
(if dest-file
(void)
(car xs))))
;; Returns (values <tag-or-#f> <form?>)
(define xref-binding-tag

View File

@ -75,14 +75,14 @@ noted above). Two numbers are @scheme[equal?] when they are
@; ----------------------------------------
@section{Number Types}
@defproc[(number? [v any/c]) boolean?]{ Returns @scheme[#t] if @scheme[v]
@defproc[(number? [v any/c]) boolean?]{Returns @scheme[#t] if @scheme[v]
is a number, @scheme[#f] otherwise.
@examples[(number? 1) (number? 2+3i) (number? "hello")]}
@defproc[(complex? [v any/c]) boolean?]{ Returns @scheme[(number? #,
@scheme[v])], because all numbers are @tech{complex numbers}.}
@defproc[(complex? [v any/c]) boolean?]{ Returns @scheme[(number? v)],
because all numbers are @tech{complex numbers}.}
@defproc[(real? [v any/c]) boolean?]{ Returns @scheme[#t] if @scheme[v] is

View File

@ -133,19 +133,28 @@ the binding and its original name.}
@defproc[(xref-render [xref xref?]
[doc part?]
[dest path-string?]
[dest (or/c path-string? false/c)]
[#:render% using-render% (subclass?/c render%)
(render-mixin render%)])
void?]{
(render-mixin render%)]
[#:refer-to-existing-files? use-existing? any/c (not dest)])
(or/c void? any/c)]{
Renders @scheme[doc] using the cross-reference info in @scheme[xref]
to the destination @scheme[dest]. For example, @scheme[doc] might be a
generated document of search results using link tags described in
@scheme[xref].
If @scheme[dest] is @scheme[#f], no file is written, and the result is
an X-expression for the rendered page. Otherwise, the file
@scheme[dest] is written and the result is @|void-const|.
The optional @scheme[using-render%] argument is as for
@scheme[load-xref]. It determines the kind of output that is
generated.}
generated.
If @scheme[use-existing?] is true, then files referenced during
rendering (such as image files) are referenced from their existing
locations, instead of copying to the directory of @scheme[dest].}
@defproc[(xref-index [xref xref?]) (listof entry?)]{