bkyk8rc3zvpnsf5inmcqq4n3k98cv6hj-my-site-hyper-literate-git.test.suzanne.soy-0.0.1

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

manual-bib.rkt (2871B)


      1 #lang scheme/base
      2 (require racket/contract/base
      3          "../decode.rkt"
      4          "../struct.rkt"
      5          "../basic.rkt"
      6          "on-demand.rkt"
      7          (only-in "../core.rkt" make-style)
      8          "manual-sprop.rkt"
      9          "manual-utils.rkt"
     10          "manual-style.rkt")
     11 
     12 (define-struct a-bib-entry (key val))
     13 
     14 (provide/contract
     15  [cite ((string?) () #:rest (listof string?) . ->* . element?)]
     16  [bib-entry ((#:key string? #:title (or/c false/c pre-content?))
     17              (#:is-book? boolean? #:author (or/c false/c pre-content?) 
     18                          #:location (or/c false/c pre-content?) 
     19                          #:date (or/c false/c pre-content?) 
     20                          #:url (or/c false/c pre-content?)
     21                          #:note (or/c false/c pre-content?))
     22              . ->* .
     23              a-bib-entry?)]
     24  [rename a-bib-entry? bib-entry? (any/c . -> . boolean?)]
     25  [bibliography (() (#:tag string?) #:rest (listof a-bib-entry?) . ->* . part?)]) 
     26 
     27 (define (cite key . keys)
     28   (make-element
     29    #f
     30    (list "["
     31          (let loop ([keys (cons key keys)])
     32            (if (null? (cdr keys))
     33              (make-link-element
     34               #f
     35               (list (car keys))
     36               `(cite ,(car keys)))
     37              (make-element
     38               #f
     39               (list (loop (list (car keys)))
     40                     ", "
     41                     (loop (cdr keys))))))
     42          "]")))
     43 
     44 (define (bib-entry #:key key
     45                    #:title title
     46                    #:is-book? [is-book? #f]
     47                    #:author [author #f]
     48                    #:location [location #f]
     49                    #:date [date #f]
     50                    #:url [url #f]
     51                    #:note [note #f])
     52   (make-a-bib-entry
     53    key
     54    (make-element
     55     "bibentry"
     56     (append
     57      (if author `(,@(decode-content (list author)) ", ") null)
     58      (if is-book? null '(ldquo))
     59      (if is-book?
     60        (list (italic title))
     61        (decode-content (list title)))
     62      (if location '(",") '("."))
     63      (if is-book? null '(rdquo))
     64      (if location
     65        `(" " ,@(decode-content (list location)) ,(if date "," "."))
     66        null)
     67      (if date `(" " ,@(decode-content (list date)) ".") null)
     68      (if url `(" " ,(link url (tt url))) null)
     69      (if note (decode-content (list note)) null)))))
     70 
     71 (define-on-demand bib-style (make-style "RBibliography" scheme-properties))
     72 
     73 (define (bibliography #:tag [tag "doc-bibliography"] . citations)
     74   (make-unnumbered-part
     75    #f
     76    `((part ,tag))
     77    '("Bibliography")
     78    '()
     79    null
     80    (make-flow
     81     (list
     82      (make-table
     83       bib-style
     84       (map (lambda (c)
     85              (let ([key (a-bib-entry-key c)]
     86                    [val (a-bib-entry-val c)])
     87                (list
     88                 (to-flow (make-target-element #f `("[" ,key "]") `(cite ,key)))
     89                 flow-spacer
     90                 (to-flow val))))
     91            citations))))
     92    null))