From e2f63c61c815369a66fb688d55bb21c9ec95b1c3 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 24 Apr 2019 15:56:40 -0700 Subject: [PATCH] fixen --- quad/quadwriter/core.rkt | 28 ++++++++++++++++++++++------ quad/quadwriter/lang-helper.rkt | 3 +++ quad/quadwriter/main.rkt | 10 ++++++---- quad/quadwriter/markdown.rkt | 8 ++++---- quad/quadwriter/tags.rkt | 2 +- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/quad/quadwriter/core.rkt b/quad/quadwriter/core.rkt index 15d223c9..be3acccc 100644 --- a/quad/quadwriter/core.rkt +++ b/quad/quadwriter/core.rkt @@ -4,6 +4,7 @@ racket/match racket/list sugar/list + txexpr/base racket/date pitfall quad @@ -13,7 +14,7 @@ "attrs.rkt" "param.rkt" "font.rkt") -(provide hrbr lbr pbr render-pdf) +(provide qexpr-para-break hrbr lbr pbr render-pdf) (define-quad string-quad quad ()) @@ -509,17 +510,31 @@ ;; (that is, just after a paragraph break) ;; they need to be installed before line wrap ;; to be compatible with first-fit and best-fit. + + ;; stick a pbr on the front if there isn't one already + ;; because of the "lookahead" style of iteration + (define qs (match qs-in + [(list (? para-break?) _ ...) qs-in] + [_ (cons pbr qs-in)])) (for/fold ([qs-out null] #:result (reverse qs-out)) - ([q (in-list qs-in)] - [next-q (in-list (cdr qs-in))]) + ([q (in-list qs)] + [next-q (in-list (cdr qs))]) (match (and (para-break? q) (quad-ref next-q 'first-line-indent 0)) [(or #false 0) (cons next-q qs-out)] [indent-val (list* next-q (make-quad #:type first-line-indent #:attrs (quad-attrs next-q) #:size (pt indent-val 0)) qs-out)]))) + + +(define qexpr-para-break '(q ((break "paragraph")))) +(define (replace-para-breaks x) + (map-elements (λ (el) + (match el + [(== qexpr-para-break) pbr] + [_ el])) x)) -(define (render-pdf xs pdf-path) +(define (render-pdf x pdf-path) (define pdf (make-pdf #:compress #t #:auto-first-page #f #:output-path pdf-path @@ -530,8 +545,9 @@ (parameterize ([current-pdf pdf] [verbose-quad-printing? #false]) (setup-font-path-table! pdf-path) - (let* ([x (qexpr->quad `(q ((font-family ,default-font-family) - (font-size ,(number->string default-font-size))) ,xs))] + (let* ([x (replace-para-breaks x)] + [x (qexpr->quad `(q ((font-family ,default-font-family) + (font-size ,(number->string default-font-size))) ,x))] [x (atomize x #:attrs-proc handle-cascading-attrs)] [x (time-name hyphenate (handle-hyphenate x))] [x (map ->string-quad x)] diff --git a/quad/quadwriter/lang-helper.rkt b/quad/quadwriter/lang-helper.rkt index e5638f24..1eedb96a 100644 --- a/quad/quadwriter/lang-helper.rkt +++ b/quad/quadwriter/lang-helper.rkt @@ -1,6 +1,7 @@ #lang debug racket/base (require (for-syntax racket/base) racket/match + pollen/tag racket/system racket/class syntax/strip-context @@ -9,6 +10,8 @@ txexpr) (provide (all-defined-out)) +(define q (default-tag-function 'q)) + (define ((make-read-syntax expander-mod pt-proc) path-string p) (strip-context (with-syntax ([PATH-STRING path-string] diff --git a/quad/quadwriter/main.rkt b/quad/quadwriter/main.rkt index 18eed02a..edc6f44b 100644 --- a/quad/quadwriter/main.rkt +++ b/quad/quadwriter/main.rkt @@ -1,12 +1,14 @@ #lang debug racket/base (require pollen/tag "lang-helper.rkt") -(provide #%top #%datum #%app #%top-interaction q) +(provide (except-out (all-from-out racket/base) #%module-begin)) -(define q (default-tag-function 'q)) (define (doc-proc strs) (apply q strs)) (make-module-begin doc-proc) (module reader racket/base (require "lang-helper.rkt") - (provide read-syntax get-info) - (define read-syntax (make-read-syntax 'quadwriter quad-at-reader))) \ No newline at end of file + (provide (rename-out [rs read-syntax]) get-info) + (define rs (make-read-syntax 'quadwriter + (λ (path ip) + (for/list ([tok (in-port read ip)]) + tok))))) \ No newline at end of file diff --git a/quad/quadwriter/markdown.rkt b/quad/quadwriter/markdown.rkt index d73574d4..45d08c04 100644 --- a/quad/quadwriter/markdown.rkt +++ b/quad/quadwriter/markdown.rkt @@ -5,7 +5,7 @@ "tags.rkt" "lang-helper.rkt") (provide (all-defined-out) - #%app #%top #%datum #%top-interaction + #%app #%top #%datum #%top-interaction require (all-from-out "tags.rkt")) (define rsquo "’") @@ -21,9 +21,9 @@ [(? null?) '(" ")] ; single nonbreaking space, so something prints [strs strs])) ;; markdown parser returns list of paragraphs - (root null (add-between strs (list pbr) - #:before-first (list pbr) - #:after-last (list pbr) + (root null (add-between strs (list qexpr-para-break) + #:before-first (list qexpr-para-break) + #:after-last (list qexpr-para-break) #:splice? #true))) (make-module-begin doc-proc) diff --git a/quad/quadwriter/tags.rkt b/quad/quadwriter/tags.rkt index 9761712b..4ee05dc7 100644 --- a/quad/quadwriter/tags.rkt +++ b/quad/quadwriter/tags.rkt @@ -94,7 +94,7 @@ (for/list ([(expr idx) (in-indexed exprs)] #:when (txexpr? expr)) (list* (get-tag expr) (cons (list 'list-index (or bullet-val (format "~a" (add1 idx)))) (get-attrs expr)) (get-elements expr))) - pbr))) + qexpr-para-break))) (define-tag-function (ol attrs exprs) (list-base attrs exprs)) (define-tag-function (ul attrs exprs) (list-base attrs exprs "•"))