|
|
@ -3,69 +3,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
(provide (all-defined-out) (all-from-out pollen/world))
|
|
|
|
(provide (all-defined-out) (all-from-out pollen/world))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax (define+provide-module-begin-in-mode stx)
|
|
|
|
(define-syntax-rule (define+provide-module-begin-in-mode MODE-ARG)
|
|
|
|
(syntax-case stx ()
|
|
|
|
(begin
|
|
|
|
[(_ mode-arg)
|
|
|
|
(provide (except-out (all-from-out racket/base) #%module-begin)
|
|
|
|
(with-syntax ([new-module-begin (format-id stx "new-module-begin")])
|
|
|
|
(rename-out [pollen-module-begin #%module-begin]))
|
|
|
|
#'(begin
|
|
|
|
(define-syntax (pollen-module-begin stx)
|
|
|
|
(provide (except-out (all-from-out racket/base) #%module-begin)
|
|
|
|
(syntax-case stx ()
|
|
|
|
(rename-out [new-module-begin #%module-begin]))
|
|
|
|
[(_ EXPR (... ...))
|
|
|
|
(define-syntax (new-module-begin stx-arg)
|
|
|
|
(with-syntax ([DOC (datum->syntax stx (world:current-main-export))]
|
|
|
|
(syntax-case stx-arg ()
|
|
|
|
[METAS (datum->syntax stx (world:current-meta-export))]
|
|
|
|
[(_ body-exprs (... ...))
|
|
|
|
[META (datum->syntax stx (world:current-meta-tag-name))]
|
|
|
|
(with-syntax ([local-meta-tag-name (format-id stx-arg (symbol->string (world:current-meta-tag-name)))]
|
|
|
|
[INNER (datum->syntax stx ''inner)])
|
|
|
|
[local-doc-export-name (format-id stx-arg (symbol->string (world:current-main-export)))]
|
|
|
|
#'(#%module-begin
|
|
|
|
[local-metas-export-name (format-id stx-arg (symbol->string (world:current-meta-export)))])
|
|
|
|
(module inner pollen/doclang-raw
|
|
|
|
(syntax-protect
|
|
|
|
;; doclang_raw is a version of scribble/doclang with the decoder disabled
|
|
|
|
#'(#%module-begin
|
|
|
|
;; first three lines are positional arguments for doclang-raw
|
|
|
|
(module inner pollen/doclang-raw
|
|
|
|
doc-raw ; id of export
|
|
|
|
;; doclang_raw is a version of scribble/doclang with the decoder disabled
|
|
|
|
(λ(x) x) ; post-process function
|
|
|
|
;; first three lines are positional arguments for doclang-raw
|
|
|
|
() ; prepended exprs
|
|
|
|
doc-raw ; id of export
|
|
|
|
|
|
|
|
(λ(x) x) ; post-process function
|
|
|
|
|
|
|
|
() ; prepended exprs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Change behavior of undefined identifiers with #%top
|
|
|
|
;; Change behavior of undefined identifiers with #%top
|
|
|
|
;; Get project values from world
|
|
|
|
;; Get project values from world
|
|
|
|
(require pollen/top pollen/world)
|
|
|
|
(require pollen/top pollen/world)
|
|
|
|
(provide (all-defined-out) (all-from-out pollen/top pollen/world))
|
|
|
|
(provide (all-defined-out) (all-from-out pollen/top pollen/world))
|
|
|
|
|
|
|
|
EXPR (... ...))
|
|
|
|
|
|
|
|
|
|
|
|
body-exprs (... ...))
|
|
|
|
(require INNER 'inner pollen/metas) ; import inner twice: INNER for external use, 'inner for internal
|
|
|
|
|
|
|
|
|
|
|
|
(require 'inner racket/list pollen/metas)
|
|
|
|
;; in an inline module, reader-here-path and parser-mode are undefined
|
|
|
|
|
|
|
|
;; (because there's no reader)
|
|
|
|
|
|
|
|
;; but they'll become tag functions courtesy of #%top
|
|
|
|
|
|
|
|
;; so that's how we can detect if they are undefined
|
|
|
|
|
|
|
|
(define here-path (if (procedure? inner:reader-here-path)
|
|
|
|
|
|
|
|
"anonymous-module"
|
|
|
|
|
|
|
|
inner:reader-here-path))
|
|
|
|
|
|
|
|
(define parser-mode (if (procedure? inner:parser-mode)
|
|
|
|
|
|
|
|
MODE-ARG
|
|
|
|
|
|
|
|
inner:parser-mode))
|
|
|
|
|
|
|
|
|
|
|
|
;; in an inline module, reader-here-path and parser-mode are undefined
|
|
|
|
;; set up the DOC export
|
|
|
|
;; (because there's no reader)
|
|
|
|
(define doc-elements (if (list? doc-raw) ; discard all newlines at front of file
|
|
|
|
;; but they'll become tag functions courtesy of #%top
|
|
|
|
((dynamic-require 'racket/list 'dropf) doc-raw (λ(i) (equal? i "\n")))
|
|
|
|
;; so that's how we can detect if they are undefined
|
|
|
|
doc-raw)) ; single line
|
|
|
|
(define here-path (if (procedure? inner:reader-here-path)
|
|
|
|
(define doc-with-metas (list* 'placeholder-root `(META (here-path ,here-path)) doc-elements))
|
|
|
|
"anonymous-module"
|
|
|
|
(define-values (doc-without-metas METAS) (split-metas-to-hash doc-with-metas))
|
|
|
|
inner:reader-here-path))
|
|
|
|
(define DOC
|
|
|
|
(define parser-mode (if (procedure? inner:parser-mode)
|
|
|
|
(let ([proc (cond
|
|
|
|
mode-arg
|
|
|
|
[(equal? parser-mode world:mode-pagetree)
|
|
|
|
inner:parser-mode))
|
|
|
|
(λ xs ((dynamic-require 'pollen/pagetree 'decode-pagetree) xs))]
|
|
|
|
|
|
|
|
;; 'root is the hook for the decoder function.
|
|
|
|
|
|
|
|
;; If it's not a defined identifier, it just hits #%top and becomes `(root ,@body ...)
|
|
|
|
|
|
|
|
[(equal? parser-mode world:mode-markup) root]
|
|
|
|
|
|
|
|
[(equal? parser-mode world:mode-markdown)
|
|
|
|
|
|
|
|
(λ xs (apply root (apply (compose1 (dynamic-require 'markdown 'parse-markdown) string-append)
|
|
|
|
|
|
|
|
(map (dynamic-require 'pollen/decode 'to-string) xs))))]
|
|
|
|
|
|
|
|
;; for preprocessor output, just make a string.
|
|
|
|
|
|
|
|
[else (λ xs (apply string-append (map (dynamic-require 'pollen/decode 'to-string) xs)))])]
|
|
|
|
|
|
|
|
[doc-elements-without-metas (cdr doc-without-metas)])
|
|
|
|
|
|
|
|
(apply proc doc-elements-without-metas)))
|
|
|
|
|
|
|
|
|
|
|
|
(define doc-with-metas
|
|
|
|
;; hide the exports that were only for internal use.
|
|
|
|
`(placeholder-root
|
|
|
|
(provide DOC METAS (except-out (all-from-out INNER) doc-raw #%top))))]))))
|
|
|
|
,@(cons `(local-meta-tag-name (here-path ,here-path))
|
|
|
|
|
|
|
|
(if (list? doc-raw)
|
|
|
|
|
|
|
|
(dropf doc-raw (λ(i) (equal? i "\n"))) ; discard all newlines at front of file
|
|
|
|
|
|
|
|
doc-raw))))
|
|
|
|
|
|
|
|
(define-values (doc-without-metas metas) (split-metas-to-hash doc-with-metas)) ; split out the metas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; set up the 'doc export
|
|
|
|
|
|
|
|
(require pollen/decode)
|
|
|
|
|
|
|
|
(define doc (apply (cond
|
|
|
|
|
|
|
|
[(equal? parser-mode world:mode-pagetree) (λ xs ((dynamic-require 'pollen/pagetree 'decode-pagetree) xs))]
|
|
|
|
|
|
|
|
;; 'root is the hook for the decoder function.
|
|
|
|
|
|
|
|
;; If it's not a defined identifier, it just hits #%top and becomes `(root ,@body ...)
|
|
|
|
|
|
|
|
[(equal? parser-mode world:mode-markup) root]
|
|
|
|
|
|
|
|
[(equal? parser-mode world:mode-markdown) (λ xs (apply root (apply (compose1 (dynamic-require 'markdown 'parse-markdown) string-append) (map to-string xs))))]
|
|
|
|
|
|
|
|
;; for preprocessor output, just make a string.
|
|
|
|
|
|
|
|
[else (λ xs (apply string-append (map to-string xs)))]) ; default mode is preprocish
|
|
|
|
|
|
|
|
(cdr doc-without-metas))) ;; cdr strips placeholder-root tag
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; hide the exports that were only for internal use.
|
|
|
|
|
|
|
|
(provide (rename-out [metas local-metas-export-name])
|
|
|
|
|
|
|
|
(rename-out [doc local-doc-export-name])
|
|
|
|
|
|
|
|
(except-out (all-from-out 'inner) doc-raw #%top)))))]))))]))
|
|
|
|
|
|
|
|