improve rendering of titles with empty numbers

This commit is contained in:
Matthew Flatt 2016-08-13 12:45:50 -06:00
parent 495630e001
commit 3e1c63c93a

View File

@ -72,36 +72,41 @@
#f) #f)
(define/public (format-number number sep [keep-separator? #f]) (define/public (format-number number sep [keep-separator? #f])
(if (or (null? number) (cond
(andmap (lambda (x) (or (not x) (equal? x ""))) [(or (null? number)
number) (andmap (lambda (x) (or (not x) (equal? x "")))
(and (not (car number)) number)
(not (ormap number? number)))) (and (not (car number))
null (not (ormap number? number))))
(cons (let ([s (string-append null]
(apply [else
string-append (define result-s
(map (lambda (n) (let ([s (string-append
(cond (apply
[(number? n) (format "~a." n)] string-append
[(or (not n) (string? n)) ""] (map (lambda (n)
[(pair? n) (string-append (car n) (cadr n))])) (cond
(reverse (cdr number)))) [(number? n) (format "~a." n)]
(if (and (car number) [(or (not n) (string? n)) ""]
(not (equal? "" (car number)))) [(pair? n) (string-append (car n) (cadr n))]))
(if (pair? (car number)) (reverse (cdr number))))
(if keep-separator? (if (and (car number)
(string-append (caar number) (not (equal? "" (car number))))
(cadar number)) (if (pair? (car number))
(caar number)) (if keep-separator?
(format "~a." (car number))) (string-append (caar number)
""))]) (cadar number))
(if (or keep-separator? (caar number))
(pair? (car number)) (format "~a." (car number)))
(equal? s "")) ""))])
s (if (or keep-separator?
(substring s 0 (sub1 (string-length s))))) (pair? (car number))
sep))) (equal? s ""))
s
(substring s 0 (sub1 (string-length s))))))
(if (equal? result-s "")
null
(cons result-s sep))]))
(define/public (number-depth number) (define/public (number-depth number)
(if (null? number) (if (null? number)