modify parse behavior to discard newlines at the beginning of input file

pull/15/merge
Matthew Butterick 10 years ago
parent a000e3f00c
commit f3b065646b

@ -81,14 +81,17 @@
(define metas (make-hash (map meta-element->assoc meta-elements)))
(values doc-without-metas metas))
(require racket/list)
(define doc-with-metas
(let ([doc-raw (if (equal? parser-mode world:mode-markdown)
(apply (compose1 (dynamic-require 'markdown 'parse-markdown) string-append) doc-raw)
doc-raw)])
`(placeholder-root
,@(cons (meta 'here-path: here-path)
;; cdr strips initial linebreak, but make sure doc-raw isn't blank
(if (and (list? doc-raw) (> (length doc-raw) 0) (equal? (car doc-raw) "\n")) (cdr doc-raw) doc-raw)))))
(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))

Loading…
Cancel
Save