fix breakage

main
Matthew Butterick 5 years ago
parent 036ca24fc4
commit 0006c02a10

@ -7,6 +7,7 @@
line-break line-break
page-break page-break
column-break column-break
hr-break
q:para-break q:para-break
q:line-break q:line-break
q:page-break q:page-break

@ -23,9 +23,9 @@
;; markdown parser returns list of paragraphs ;; markdown parser returns list of paragraphs
(root null (match strs (root null (match strs
[(list str) strs] [(list str) strs]
[_ (add-between strs (list q:para-break) [_ (add-between strs (list para-break)
#:before-first (list q:para-break) #:before-first (list para-break)
#:after-last (list q:para-break) #:after-last (list para-break)
#:splice? #true)]))) #:splice? #true)])))
(make-module-begin doc-proc) (make-module-begin doc-proc)

@ -1,5 +1,6 @@
#lang debug racket/base #lang debug racket/base
(require racket/match (require (for-syntax racket/base racket/syntax)
racket/match
txexpr/base txexpr/base
racket/contract racket/contract
racket/file racket/file
@ -21,35 +22,51 @@
(define (setup-pdf-path pdf-path-arg) (define (setup-pdf-path pdf-path-arg)
(define fallback-path (build-path (find-system-path 'temp-dir) "quadwriter-temp.pdf")) (define fallback-path (build-path (find-system-path 'temp-dir) "quadwriter-temp.pdf"))
(path->complete-path (simplify-path (expand-user-path (->path (or pdf-path-arg fallback-path)))))) (path->complete-path (simplify-path (expand-user-path (->path (or pdf-path-arg fallback-path))))))
#|
(define para-break '(q ((break "para")))) (define para-break '(q ((break "para"))))
(define line-break '(q ((break "line")))) (define line-break '(q ((break "line"))))
(define page-break '(q ((break "page")))) (define page-break '(q ((break "page"))))
(define column-break '(q ((break "column")))) (define column-break '(q ((break "column"))))
(define hr-break '(q ((break "hr"))))
|#
(define-syntax (define-break-types stx)
(syntax-case stx ()
[(_ ALL-BREAKS-ID . TYPES)
(with-syntax ([((TYPE-BREAK TYPE-STR Q:TYPE-BREAK) ...)
(for/list ([type (in-list (syntax->list #'TYPES))])
(list
(format-id #'TYPES "~a-break" type)
(symbol->string (syntax->datum type))
(format-id #'TYPES "q:~a-break" type)))])
#'(begin
(define TYPE-BREAK '(q ((break TYPE-STR)))) ...
(define ALL-BREAKS-ID (list (cons TYPE-BREAK Q:TYPE-BREAK) ...))))]))
(define-break-types all-breaks para line page column hr)
(define (replace-breaks x) (define (replace-breaks x)
(map-elements (λ (el) (map-elements (λ (el)
(match el (cond
[(== para-break) q:para-break] [(assoc el all-breaks) => cdr]
[(== line-break) q:line-break] [else el])) x))
[(== column-break) q:column-break]
[(== page-break) q:page-break]
[_ el])) x))
(define (handle-hyphenate qs) (define (handle-hyphenate qs)
;; find quads that want hyphenation and split them into smaller pieces ;; find quads that want hyphenation and split them into smaller pieces
;; do this before ->string-quad so that it can handle the sizing promises ;; do this before ->string-quad so that it can handle the sizing promises
(apply append (apply append
(for/list ([q (in-list qs)]) (for/list ([q (in-list qs)])
(match (quad-ref q :hyphenate) (match (quad-ref q :hyphenate)
[#false (list q)] [#false (list q)]
[_ (for*/list ([str (in-list (quad-elems q))] [_ (for*/list ([str (in-list (quad-elems q))]
[hyphen-char (in-value #\u00AD)] [hyphen-char (in-value #\u00AD)]
[hstr (in-value (hyphenate str hyphen-char [hstr (in-value (hyphenate str hyphen-char
#:min-left-length 3 #:min-left-length 3
#:min-right-length 3))] #:min-right-length 3))]
[substr (in-list (regexp-match* (regexp (string hyphen-char)) hstr #:gap-select? #t))]) [substr (in-list (regexp-match* (regexp (string hyphen-char)) hstr #:gap-select? #t))])
(struct-copy quad q [elems (list substr)]))])))) (struct-copy quad q [elems (list substr)]))]))))
(define (handle-cascading-attrs attrs) (define (handle-cascading-attrs attrs)
(resolve-font-path attrs) (resolve-font-path attrs)
@ -66,12 +83,12 @@
(setup-font-path-table! pdf-path) (setup-font-path-table! pdf-path)
[define atomized-qs [define atomized-qs
(time-log atomize (atomize the-quad (time-log atomize (atomize the-quad
#:attrs-proc handle-cascading-attrs #:attrs-proc handle-cascading-attrs
#:missing-glyph-action 'fallback #:missing-glyph-action 'fallback
#:fallback "fallback" #:fallback "fallback"
#:emoji "emoji" #:emoji "emoji"
#:math "math" #:math "math"
#:font-path-resolver resolve-font-path))] #:font-path-resolver resolve-font-path))]
[define hyphenated-qs (time-log hyphenate (handle-hyphenate atomized-qs))] [define hyphenated-qs (time-log hyphenate (handle-hyphenate atomized-qs))]
[define stringified-qs (map ->string-quad hyphenated-qs)] [define stringified-qs (map ->string-quad hyphenated-qs)]
[define indented-qs (insert-first-line-indents stringified-qs)] [define indented-qs (insert-first-line-indents stringified-qs)]
@ -81,9 +98,9 @@
;; page size can be specified by name, or measurements. ;; page size can be specified by name, or measurements.
;; explicit measurements from page-height and page-width supersede those from page-size. ;; explicit measurements from page-height and page-width supersede those from page-size.
(match-define (list page-width page-height) (for/list ([k (list :page-width :page-height)]) (match-define (list page-width page-height) (for/list ([k (list :page-width :page-height)])
(match (quad-ref (car qs) k) (match (quad-ref (car qs) k)
[#false #false] [#false #false]
[val (parse-dimension val 'round)]))) [val (parse-dimension val 'round)])))
;; `make-pdf` will sort out conflicts among page dimensions ;; `make-pdf` will sort out conflicts among page dimensions
(make-pdf #:compress compress? (make-pdf #:compress compress?
#:auto-first-page #false #:auto-first-page #false

@ -26,8 +26,7 @@
:display (symbol->string (gensym))) :display (symbol->string (gensym)))
attrs) exprs)) attrs) exprs))
(define-tag-function (hr attrs exprs) (define-tag-function (hr attrs exprs) hr-break)
q:hr-break)
(define-tag-function (blockquote attrs exprs) (define-tag-function (blockquote attrs exprs)
(qexpr (append (list->attrs (qexpr (append (list->attrs

Loading…
Cancel
Save