scribble-enhanced/collects/scribblings/scribble/utils.ss
Matthew Flatt 41c752b9b4 make scribble reader section fit narrower column
svn: r6265

original commit: 3c25a6ad93e78433981e798b920f9931e9d605c6
2007-05-24 10:36:03 +00:00

50 lines
1.6 KiB
Scheme

(module utils mzscheme
(require (lib "struct.ss" "scribble")
(lib "manual.ss" "scribble")
(prefix scheme: (lib "scheme.ss" "scribble"))
(prefix scribble: (lib "reader.ss" "scribble"))
(lib "string.ss"))
(provide at
litchar/lines
scribble-examples)
(define at "@")
(define (litchar/lines s)
(let ([strs (regexp-split #rx"\n" s)])
(if (= 1 (length strs))
(litchar s)
(make-table
#f
(map (lambda (s)
(list (make-flow (list (make-paragraph (list (litchar s)))))))
strs)))))
(define (as-flow e)
(make-flow (list (if (flow-element? e)
e
(make-paragraph (list e))))))
(define spacer (hspace 2))
(define (scribble-examples . lines)
(make-table
#f
(map (lambda (line)
(let ([line (if (string? line)
(list (litchar/lines line)
(scheme:to-paragraph
(let ([p (open-input-string line)])
(port-count-lines! p)
(if (regexp-match? #rx"\n" line)
(scribble:read-syntax #f p)
(scribble:read p)))))
line)])
(list (as-flow spacer)
(as-flow (if line (car line) ""))
(as-flow (if line (make-paragraph (list spacer "reads as" spacer)) ""))
(as-flow (if line (cadr line) "")))))
lines))))