markdown working

pull/9/head
Matthew Butterick 11 years ago
parent 51cfc26ef0
commit 95478ba824

@ -35,9 +35,22 @@
(require 'inner) (require 'inner)
;; set the parser mode based on reader mode
(define parser-mode
(if (equal? reader-mode world:reader-mode-auto)
(let* ([file-ext-pattern (pregexp "\\w+$")]
[here-ext (string->symbol (car (regexp-match file-ext-pattern inner-here-path)))])
(cond
[(equal? here-ext world:ptree-source-ext) world:reader-mode-ptree]
[(equal? here-ext world:markup-source-ext) world:reader-mode-markup]
[(equal? here-ext world:markdown-source-ext) world:reader-mode-markdown]
[else world:reader-mode-preproc]))
reader-mode))
;; Split out the metas. ;; Split out the metas.
(require txexpr) (require txexpr)
(define (split-metas-to-hash tx) (define (split-metas-to-hash tx) ; helper function
;; return tx without metas, and meta hash ;; return tx without metas, and meta hash
(define is-meta-element? (λ(x) (and (txexpr? x) (equal? 'meta (car x))))) (define is-meta-element? (λ(x) (and (txexpr? x) (equal? 'meta (car x)))))
(define-values (doc-without-metas meta-elements) (define-values (doc-without-metas meta-elements)
@ -47,7 +60,7 @@
(values doc-without-metas metas)) (values doc-without-metas metas))
(define doc-txexpr (define doc-txexpr
(let ([doc-raw (if (equal? reader-mode world:reader-mode-markdown) (let ([doc-raw (if (equal? parser-mode world:reader-mode-markdown)
(apply (compose1 (dynamic-require 'markdown 'parse-markdown) string-append) doc-raw) (apply (compose1 (dynamic-require 'markdown 'parse-markdown) string-append) doc-raw)
doc-raw)]) doc-raw)])
`(placeholder-root `(placeholder-root
@ -61,27 +74,14 @@
;; set up the 'doc export ;; set up the 'doc export
(require pollen/decode) (require pollen/decode)
;; set the parser mode based on reader mode
(define parser-mode
(if (reader-mode . equal? . world:reader-mode-auto)
(let* ([file-ext-pattern (pregexp "\\w+$")]
[here-ext (car (regexp-match file-ext-pattern inner-here-path))])
(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) 'apply-root]
[else world:reader-mode-preproc]))
reader-mode))
(define doc (apply (cond (define doc (apply (cond
[(equal? parser-mode world:reader-mode-ptree) [(equal? parser-mode world:reader-mode-ptree)
(λ xs (decode (cons world:ptree-root-node xs) (λ xs (decode (cons world:ptree-root-node xs)
#:xexpr-elements-proc (λ(xs) (filter (compose1 not (def/c whitespace?)) xs))))] #:xexpr-elements-proc (λ(xs) (filter (compose1 not (def/c whitespace?)) xs))))]
;; 'root is the hook for the decoder function. ;; 'root is the hook for the decoder function.
;; If it's not a defined identifier, it just hits #%top and becomes `(root ,@body ...) ;; If it's not a defined identifier, it just hits #%top and becomes `(root ,@body ...)
[(equal? parser-mode world:reader-mode-markup) root] [(or (equal? parser-mode world:reader-mode-markup)
[(equal? parser-mode world:reader-mode-markdown) (λ xs `(root ,@xs))] ; do nothing, it's already decoded (equal? parser-mode world:reader-mode-markdown)) root]
;; for preprocessor output, just make a string. ;; for preprocessor output, just make a string.
[else (λ xs (apply string-append (map to-string xs)))]) [else (λ xs (apply string-append (map to-string xs)))])
(cdr doc-without-metas))) ;; cdr strips placeholder-root tag (cdr doc-without-metas))) ;; cdr strips placeholder-root tag

Loading…
Cancel
Save