|
|
|
@ -46,18 +46,22 @@
|
|
|
|
|
(define metas (make-hash (map meta-element->assoc meta-elements)))
|
|
|
|
|
(values doc-without-metas metas))
|
|
|
|
|
|
|
|
|
|
(define doc-txexpr `(placeholder-root
|
|
|
|
|
,@(cons (meta 'here: inner-here)
|
|
|
|
|
(cons (meta 'here-path: inner-here-path)
|
|
|
|
|
;; cdr strips initial linebreak, but make sure doc-raw isn't blank
|
|
|
|
|
(if (and (list? doc-raw) (> 0 (length doc-raw))) (cdr doc-raw) doc-raw)))))
|
|
|
|
|
|
|
|
|
|
(define doc-txexpr
|
|
|
|
|
(let ([doc-raw (if (equal? reader-mode world:reader-mode-markdown)
|
|
|
|
|
(apply (compose1 (dynamic-require 'markdown 'parse-markdown) string-append) doc-raw)
|
|
|
|
|
doc-raw)])
|
|
|
|
|
`(placeholder-root
|
|
|
|
|
,@(cons (meta 'here: inner-here)
|
|
|
|
|
(cons (meta 'here-path: inner-here-path)
|
|
|
|
|
;; cdr strips initial linebreak, but make sure doc-raw isn't blank
|
|
|
|
|
(if (and (list? doc-raw) (> 0 (length doc-raw))) (cdr doc-raw) doc-raw))))))
|
|
|
|
|
|
|
|
|
|
(define-values (doc-without-metas metas) (split-metas-to-hash doc-txexpr))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; set up the 'doc export
|
|
|
|
|
(require pollen/decode)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; set the parser mode based on reader mode
|
|
|
|
|
(define parser-mode
|
|
|
|
|
(if (reader-mode . equal? . world:reader-mode-auto)
|
|
|
|
@ -66,21 +70,21 @@
|
|
|
|
|
(cond
|
|
|
|
|
[(equal? (string->symbol here-ext) world:ptree-source-ext) world:reader-mode-ptree]
|
|
|
|
|
[(equal? (string->symbol here-ext) world:markup-source-ext) world:reader-mode-markup]
|
|
|
|
|
[(equal? (string->symbol here-ext) world:markdown-source-ext) world:reader-mode-markdown]
|
|
|
|
|
[(equal? (string->symbol here-ext) world:markdown-source-ext) 'apply-root]
|
|
|
|
|
[else world:reader-mode-preproc]))
|
|
|
|
|
reader-mode))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define doc (apply (cond
|
|
|
|
|
[(equal? parser-mode world:reader-mode-ptree)
|
|
|
|
|
(λ xs (decode (cons world:ptree-root-node xs)
|
|
|
|
|
#:xexpr-elements-proc (λ(xs) (filter (compose1 not (def/c whitespace?)) 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:reader-mode-markup) root]
|
|
|
|
|
[(equal? parser-mode world:reader-mode-markdown) (compose1 (λ(x) `(root ,@x)) (dynamic-require 'markdown 'parse-markdown) string-append)]
|
|
|
|
|
;; for preprocessor output, just make a string.
|
|
|
|
|
[else (λ xs (apply string-append (map to-string xs)))])
|
|
|
|
|
(cdr doc-without-metas))) ;; cdr strips placeholder-root tag
|
|
|
|
|
[(equal? parser-mode world:reader-mode-ptree)
|
|
|
|
|
(λ xs (decode (cons world:ptree-root-node xs)
|
|
|
|
|
#:xexpr-elements-proc (λ(xs) (filter (compose1 not (def/c whitespace?)) 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:reader-mode-markup) root]
|
|
|
|
|
[(equal? parser-mode world:reader-mode-markdown) (λ xs `(root ,@xs))] ; do nothing, it's already decoded
|
|
|
|
|
;; for preprocessor output, just make a string.
|
|
|
|
|
[else (λ xs (apply string-append (map to-string xs)))])
|
|
|
|
|
(cdr doc-without-metas))) ;; cdr strips placeholder-root tag
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide metas doc
|
|
|
|
|