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

Loading…
Cancel
Save