improve handling of scribble render

pull/155/head
Matthew Butterick 7 years ago
parent 1886bb7f5d
commit 25ca9e9426

@ -1 +1 @@
1502141536 1502144359

@ -162,18 +162,20 @@
(define (render-scribble-source source-path . _) (define (render-scribble-source source-path . _)
;((complete-path?) #:rest any/c . ->* . string?) ;((complete-path?) #:rest any/c . ->* . string?)
(define scribble-render (parameterize ([current-namespace (make-base-namespace)]) (local-require scribble/core scribble/manual (prefix-in scribble- scribble/render))
(dynamic-require 'scribble/render 'render))) (define source-dir (dirname source-path))
(time (parameterize ([current-directory (->complete-path (dirname source-path))]) ;; make fresh namespace for scribble rendering (avoids dep/zo caching)
;; if there's a compiled zo file for the Scribble file, (time (parameterize ([current-namespace (make-base-namespace)]
;; (as is usually the case in existing packages) [current-directory (->complete-path source-dir)])
;; it will foul up the render (namespace-attach-module (namespace-anchor->namespace render-module-ns) 'scribble/core)
;; so recompile first to avoid "can't redefine a constant" errors. (namespace-attach-module (namespace-anchor->namespace render-module-ns) 'scribble/manual)
(managed-compile-zo source-path)
;; scribble/lp files have their doc export in a 'doc submodule, so check both locations ;; scribble/lp files have their doc export in a 'doc submodule, so check both locations
(define doc (dynamic-require source-path 'doc (define doc
(λ () (dynamic-require `(submod ,source-path doc) 'doc [cond
(λ () #f))))) [(dynamic-require source-path 'doc (λ () #f))]
[(dynamic-require `(submod ,source-path doc) 'doc (λ () #f))]
[else #f]])
;; BTW this next action has side effects: scribble will copy in its core files if they don't exist. ;; BTW this next action has side effects: scribble will copy in its core files if they don't exist.
(when doc (when doc
(scribble-render (list doc) (list source-path))))) (scribble-render (list doc) (list source-path)))))

Loading…
Cancel
Save