diff --git a/decode.rkt b/decode.rkt index 3a349f4..0b7b190 100644 --- a/decode.rkt +++ b/decode.rkt @@ -237,6 +237,16 @@ +;; recursive whitespace test +(define/contract (whitespace? x) + (any/c . -> . boolean?) + (cond + [(or (string? x) (symbol? x)) (->boolean (regexp-match #px"^\\s+$" (->string x)))] + [(equal? "" x) #t] ; empty string is deemed whitespace + [(or (list? x) (vector? x)) (andmap whitespace? (->list x))] + [else #f])) + + ;; is x a paragraph break? (define/contract (paragraph-break? x #:pattern [paragraph-pattern #px"^\n\n+$"]) ((any/c) (#:pattern pregexp?) . ->* . boolean?) diff --git a/main.rkt b/main.rkt index 48d6574..e877dbf 100644 --- a/main.rkt +++ b/main.rkt @@ -42,28 +42,35 @@ (cons `(meta "here" ,inner-here) meta-elements))))) + + ;; set up the 'main export + (require pollen/decode) + (require (only-in racket/list filter-not)) (define here-ext (car (regexp-match #px"\\w+$" inner-here-path))) (define wants-decoder? (member here-ext (list "pd" "ptree"))) - (define main (apply (if wants-decoder? - ;; 'root is the hook for the decoder function. - ;; If it's not a defined identifier, it just hits #%top and becomes `(root ,@body ...) - root - ;; for preprocessor output, just make a string. Converts x-expressions to HTML. - (λ xs (apply string-append (map (dynamic-require 'xml 'xexpr->string) xs)))) - (cdr main-without-metas))) ;; cdr strips placeholder-root tag - - - ;; derive 'here & 'here-path from the hash (because they might have been overridden in the source) - (define here (hash-ref metas "here")) - (define here-path (hash-ref metas "here-path")) - - (provide metas main here here-path - ;; hide the exports that were only for internal use. - (except-out (all-from-out 'inner) inner-here inner-here-path main-raw #%top)) - - ;; for output in DrRacket - (module+ main - (if wants-decoder? - (print main) - (display main))))) + ;(print (cdr main-without-metas)) + (define main (apply (cond + [(equal? here-ext "ptree") (λ xs (decode (cons 'ptree-root xs) + #:xexpr-elements-proc (λ(xs) (filter-not 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 ...) + [wants-decoder? root] + ;; for preprocessor output, just make a string. Converts x-expressions to HTML. + [else (λ xs (apply string-append (map (dynamic-require 'xml 'xexpr->string) xs)))]) +(cdr main-without-metas))) ;; cdr strips placeholder-root tag + + +;; derive 'here & 'here-path from the hash (because they might have been overridden in the source) +(define here (hash-ref metas "here")) +(define here-path (hash-ref metas "here-path")) + +(provide metas main here here-path + ;; hide the exports that were only for internal use. + (except-out (all-from-out 'inner) inner-here inner-here-path main-raw #%top)) + +;; for output in DrRacket +(module+ main + (if wants-decoder? + (print main) + (display main))))) diff --git a/predicates.rkt b/predicates.rkt index 6b0e81b..03f2e2c 100644 --- a/predicates.rkt +++ b/predicates.rkt @@ -27,14 +27,6 @@ ((txexpr? x) . and . ((car x) . in? . project-block-tags))) -;; recursive whitespace test -(define+provide/contract (whitespace? x) - (any/c . -> . boolean?) - (cond - [(or (vector? x) (list? x) (set? x)) (andmap whitespace? (->list x))] - [(equal? "" x) #t] ; empty string is deemed whitespace - [(or (symbol? x) (string? x)) (->boolean (regexp-match #px"^\\s+$" (->string x)))] - [else #f]))