main
Matthew Butterick 6 years ago
parent a9025d7947
commit e2f63c61c8

@ -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)]

@ -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]

@ -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)))
(provide (rename-out [rs read-syntax]) get-info)
(define rs (make-read-syntax 'quadwriter
(λ (path ip)
(for/list ([tok (in-port read ip)])
tok)))))

@ -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)

@ -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 ""))

Loading…
Cancel
Save