-
Notifications
You must be signed in to change notification settings - Fork 0
/
citations-mcgill.rkt
1623 lines (1494 loc) · 88.8 KB
/
citations-mcgill.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#lang racket
; This module implements a citation system meant to be used in Pollen.
(provide
; To be used in author source
; ---------------------------
; Declares a work that can be then cited.
declare-work
; Alternate form for declare-work that doesn't accept an id. It renders the work in-place.
; If you use this form, the work cannot be referred to later using 'cite'.
format-work
; Actually cites the work (returns a txexpr with the formatted citation).
cite
; Get bibliography.
bibliography-ids
; Gets a bibliography-formatted citation.
bib-entry
bib-sort-value
; Gets the short-form
short-form
; To be used in your Pollen module to let the citation system
; do the work it needs to do.
; ------------------------------------------------------------
; Use this within your note tag to let this citation system transform
; the citations it created with 'cite' into back-references or to include
; short forms.
transform-cite-in-a-note
; Use during the final decode (txexpr-proc) to insert short-forms where
; they're needed.
show-necessary-short-forms)
;----------------------------------------------------------------------
; Implementation
(require pollen/core)
(require racket/contract)
(require txexpr)
(module+ test
(require rackunit))
(define work-metadata (make-hash))
(define first-place-cited (make-hash))
(define most-recent-ibid-or-supra #f)
(define short-form-used? (make-hash))
(define unidentified-work-count 0)
(define/contract (bibliography-ids #:category [category #f])
(()(#:category (or/c "jurisprudence" "secondary" "legislation" "other" #f)) . ->* . (listof string?))
(define (create-category-filter category)
(case category
[("jurisprudence") (λ (key) (member (hash-ref (hash-ref work-metadata key) 'type) '("legal-case" "legal-case-US")))]
[("secondary") (λ (key) (member (hash-ref (hash-ref work-metadata key) 'type) '("article" "chapter" "book" "magazine/news" "thesis" "proceedings" "unpublished")))]
[("legislation") (λ (key) (member (hash-ref (hash-ref work-metadata key) 'type) '("bill" "statute" "regulation" "debate")))]
[("other") (λ (key) (member (hash-ref (hash-ref work-metadata key) 'type) '("custom")))]))
(if category
(filter (create-category-filter category) (hash-keys first-place-cited))
(hash-keys first-place-cited)))
; Accessor
(define/contract (get-work-by-id id)
(string? . -> . hash?)
(hash-ref work-metadata (clean-param id)))
; Helpers
(define (declared-id? id)
(hash-has-key? work-metadata (clean-param id)))
(define-syntax-rule (when-or-empty condition lst)
(if condition lst '()))
(define (string-is-affirmative? x)
(define (member? v lst)
(list? (member v lst)))
(member? (string-downcase x) '("yes" "true" "y" "t" "#t")))
(module+ test
(check-true (string-is-affirmative? "yes"))
(check-true (string-is-affirmative? "Yes"))
(check-true (string-is-affirmative? "true"))
(check-true (string-is-affirmative? "True"))
(check-true (string-is-affirmative? "#t"))
(check-true (string-is-affirmative? "#T"))
(check-true (string-is-affirmative? "y"))
(check-true (string-is-affirmative? "Y"))
(check-true (string-is-affirmative? "t"))
(check-true (string-is-affirmative? "T"))
(check-false (string-is-affirmative? "No"))
(check-false (string-is-affirmative? ""))
(check-false (string-is-affirmative? "#F")))
(define/contract (merge-successive-strings elements)
(txexpr-elements? . -> . txexpr-elements?)
(define (conditional-merge element current-list)
(if (and (not (empty? current-list))
(string? (first current-list))
(string? element))
(cons (string-append (first current-list) element) (drop current-list 1))
(cons element current-list)))
(reverse (foldl conditional-merge '() elements)))
(module+ test
(check-equal? (merge-successive-strings '()) '())
(check-equal? (merge-successive-strings '("a")) '("a"))
(check-equal? (merge-successive-strings '(a)) '(a))
(check-equal? (merge-successive-strings '(a "b")) '(a "b"))
(check-equal? (merge-successive-strings '("a" "b")) '("ab"))
(check-equal? (merge-successive-strings '("a" a "b")) '("a" a "b"))
(check-equal? (merge-successive-strings '("a" "b" " " "c")) '("ab c"))
(check-equal? (merge-successive-strings '("a" "b" a " " b "c" c d "e" " f" g)) '("ab" a " " b "c" c d "e f" g))
)
; Citation system. Following the McGill Guide, with Chicago Manual of Style for any ambiguities.
; ----------------------------------------------------------------------------------------------
(define/contract (valid-work-type? type)
(string? . -> . boolean?)
(if (member type '("article" "chapter" "thesis" "proceedings" "unpublished" "legal-case" "legal-case-US"
"bill" "statute" "regulation" "debate" "book" "magazine/news" "custom"))
#t #f))
(module+ test
(check-true (valid-work-type? "thesis"))
(check-false (valid-work-type? "invalid work")))
(define/contract (strip-at str)
(string? . -> . string?)
(if (string-prefix? (string-downcase str) "at ")
(substring str 3)
str))
(module+ test
(check-equal? (strip-at "page 13") "page 13")
(check-equal? (strip-at "at 13") "13")
(check-equal? (strip-at "At para 12") "para 12")
(check-equal? (strip-at "cat 5") "cat 5"))
(define/contract (pinpoint-is-pages? str)
(string? . -> . boolean?)
(or (string-prefix? (string-downcase str) "p ")
(string-prefix? (string-downcase str) "pp ")
(string-prefix? (string-downcase str) "page ")
(string-prefix? (string-downcase str) "pages ")
(regexp-match-exact? #rx"([-0-9, ]*)" str)))
(module+ test
(check-true (pinpoint-is-pages? "12--39"))
(check-true (pinpoint-is-pages? "p 12"))
(check-false (pinpoint-is-pages? "para 12"))
(check-false (pinpoint-is-pages? "paras 12--14"))
(check-false (pinpoint-is-pages? "paras 12, 14"))
(check-true (pinpoint-is-pages? "pp 32, 33"))
(check-true (pinpoint-is-pages? "Page 1"))
(check-true (pinpoint-is-pages? "1"))
(check-true (pinpoint-is-pages? "1, 35")))
(define/contract (pinpoint-is-timestamp? str)
(string? . -> . boolean?)
(or (regexp-match? #px"\\d\\dh:\\d\\dm:\\d\\ds" str)
(regexp-match? #px"\\d\\dm:\\d\\ds" str)))
(module+ test
(check-false (pinpoint-is-timestamp? "12"))
(check-false (pinpoint-is-timestamp? "s 12"))
(check-true (pinpoint-is-timestamp? "00h:12m:32s"))
(check-true (pinpoint-is-timestamp? "00m:33s")))
(define (pinpoint-requires-at? str) (or (string-prefix? (strip-at str) "para") (pinpoint-is-pages? (strip-at str)) (pinpoint-is-timestamp? (strip-at str))))
(define (pinpoint-requires-comma? str) (not (pinpoint-requires-at? str)))
(define/contract (normalize-pinpoint pinpoint)
(string? . -> . string?)
(define cleaned-pinpoint (clean-param pinpoint))
(define pinpoint-without-at (strip-at cleaned-pinpoint))
(define to-replace (first (string-split pinpoint-without-at)))
(define replacement
(case (string-downcase to-replace)
[("page" "p") ""]
[("pages" "pp") ""]
[("paragraph" "para.") "para"]
[("paragraphs" "paras.") "paras"]
[("clause" "cl.") "cl"]
[("clauses" "cls.") "cls"]
[("section" "s.") "s"]
[("sections" "ss.") "ss"]
[else to-replace]))
(define pinpoint-content (string-trim (string-replace pinpoint-without-at to-replace replacement #:all? #f)))
(define (fix-plurals pinpoint)
(define (pinpoint-contains? x) (string-contains? pinpoint x))
(let ([plurals '("ss" "cls" "paras")]
[singulars '("s" "cl" "para")]
[should-be-plural? (or (string-contains? pinpoint "--")
(string-contains? pinpoint ","))])
(cond
[(ormap pinpoint-contains? plurals)
(if should-be-plural?
pinpoint
(foldl (lambda (a b result) (string-replace result a b))
pinpoint
plurals
singulars))]
[(ormap pinpoint-contains? singulars)
(if should-be-plural?
(foldl (lambda (a b result) (string-replace result a b))
pinpoint
singulars
plurals)
pinpoint)]
[else pinpoint])))
(define fixed-plurals (fix-plurals pinpoint-content))
(if (pinpoint-requires-at? cleaned-pinpoint) (format " at ~a" fixed-plurals) (format ", ~a" fixed-plurals)))
(module+ test
(check-equal? (normalize-pinpoint "page 1") " at 1")
(check-equal? (normalize-pinpoint "page\n1") " at 1")
(check-equal? (normalize-pinpoint "at page 1") " at 1")
(check-equal? (normalize-pinpoint "pages 2, 3") " at 2, 3")
(check-equal? (normalize-pinpoint "p 1--3") " at 1--3")
(check-equal? (normalize-pinpoint "paragraph 1") " at para 1")
(check-equal? (normalize-pinpoint "at clause 1") ", cl 1")
(check-equal? (normalize-pinpoint "clause 1") ", cl 1")
(check-equal? (normalize-pinpoint "cls 2--3") ", cls 2--3")
; plural/singular agreement tests
(check-equal? (normalize-pinpoint "clauses 1") ", cl 1")
(check-equal? (normalize-pinpoint "cl 2--3") ", cls 2--3")
(check-equal? (normalize-pinpoint "cl 2") ", cl 2")
(check-equal? (normalize-pinpoint "cl 2,4") ", cls 2,4")
(check-equal? (normalize-pinpoint "clauses 2,4") ", cls 2,4")
(check-equal? (normalize-pinpoint "paragraph 1--3") " at paras 1--3")
(check-equal? (normalize-pinpoint "paras. 1--3") " at paras 1--3")
(check-equal? (normalize-pinpoint "paragraphs 3") " at para 3")
(check-equal? (normalize-pinpoint "ss. 4") ", s 4")
(check-equal? (normalize-pinpoint "section 4--6") ", ss 4--6")
(check-equal? (normalize-pinpoint "s. 1") ", s 1")
(check-equal? (normalize-pinpoint "sections 1--3") ", ss 1--3"))
; potential future failure condition: singular word with 2 s's
;(check-equal? (normalize-pinpoint "lesson 1") "lesson 1"))
(define/contract (strip-http/https-protocol url)
(string? . -> . string?)
(if (string-prefix? url "https://")
(string-replace url "https://" "")
(if (string-prefix? url "http://")
(string-replace url "http://" "")
url)))
(module+ test
(check-equal? (strip-http/https-protocol "https://www.ubc.ca") "www.ubc.ca")
(check-equal? (strip-http/https-protocol "http://www.ubc.ca") "www.ubc.ca")
(check-equal? (strip-http/https-protocol "www.ubc.ca") "www.ubc.ca"))
(define/contract (year-is-necessary? citation)
(string? . -> . boolean?)
; Are the first alphanumeric characters in the citation a four-digit year? Ie. Is there a sequence of four consecutive
; digits before any letter?
(not (regexp-match? #px"[[:digit:]]{4}" (first (regexp-match #px"\\S*[[:space:]]" citation)))))
(module+ test
(check-true (year-is-necessary? "301 DLR (4th) 34"))
(check-false (year-is-necessary? "[1977] 1 SCR 193"))
(check-false (year-is-necessary? "2012 SCC 1")))
(define/contract (year-is-different? work)
(hash? . -> . boolean?)
; Is there a declared year that is different than the first four digits of the citation?
(and (hash-ref work 'year)
(not (year-is-necessary? (hash-ref work 'citation)))
(not (equal? (hash-ref work 'year) (first (regexp-match #px"[[:digit:]]{4}" (first (regexp-match #px"\\S*[[:space:]]" (hash-ref work 'citation)))))))))
(module+ test
(check-false (year-is-different? (hash 'year "2018" 'citation "2018 SCC 1")))
(check-false (year-is-different? (hash 'year #f 'citation "2018 SCC 1")))
(check-true (year-is-different? (hash 'year "2017" 'citation "[2018] 1 SCR 1")))
(check-false (year-is-different? (hash 'year "2017" 'citation "[2017] 1 SCR 1"))))
(define/contract (clean-param param)
((or/c string? #f) . -> . (or/c string? #f))
(if param (string-normalize-spaces param) param))
(module+ test
(check-false (clean-param #f))
(check-exn exn:fail? (λ () (clean-param #t)))
(check-equal? (clean-param "multi-line\nargument") "multi-line argument"))
(define/contract (get-given-from-author author)
(string? . -> . string?)
(define parts (string-split (clean-param author)))
(if (not (equal? (length parts) 2))
(raise-user-error "Specified an author (a shortcut keyword) that has fewer or more than two parts: " author)
(first parts)))
(define/contract (get-family-from-author author)
(string? . -> . string?)
(define parts (string-split (clean-param author)))
(if (not (equal? (length parts) 2))
(raise-user-error "Specified an author (a shortcut keyword) that has fewer or more than two parts: " author)
(second parts)))
(module+ test
(check-equal? (get-given-from-author "Sancho McCann") "Sancho")
(check-equal? (get-family-from-author "Sancho McCann") "McCann")
(check-exn exn:fail? (λ () (get-given-from-author "Sancho J McCann")))
(check-exn exn:fail? (λ () (get-family-from-author "Sancho J McCann")))
(check-exn exn:fail? (λ () (get-given-from-author "Sancho")))
(check-exn exn:fail? (λ () (get-family-from-author "Sancho"))))
(define/contract (extract-first-page pages)
(string? . -> . string?)
(first (regexp-match #rx"[0-9]+" pages)))
(module+ test
(check-equal? (extract-first-page "1--10") "1")
(check-equal? (extract-first-page "10") "10")
(check-equal? (extract-first-page "11--101") "11")
(check-equal? (extract-first-page "11---101") "11")
(check-equal? (extract-first-page "11-101") "11")
(check-exn exn:fail? (λ () (extract-first-page "not a page or range"))))
; ------------------------------------------------------------------------------
; These validators check that a declared work has
; the mandatory elements and has none that are incompatible
; with each other.
(define/contract (validate-work-or-die w)
(hash? . -> . void?)
(case (hash-ref w 'type)
[("article") (validate-article w)]
[("chapter") (validate-chapter w)]
[("thesis") (validate-thesis w)]
[("proceedings") (validate-proceedings w)]
[("unpublished") (validate-unpublished w)]
[("legal-case") (validate-legal-case w)]
[("legal-case-US") (validate-legal-case-US w)]
[("bill") (validate-bill w)]
[("statute") (validate-statute w)]
[("regulation") (validate-regulation w)]
[("debate") (validate-debate w)]
[("book") (validate-book w)]
[("magazine/news") (validate-magazine/news w)]
[("custom") (validate-custom w)]
[else (raise-user-error "Unrecognized type for work: " (hash-ref w 'type))]))
(module+ test
(check-not-exn (λ () (validate-work-or-die (hash 'type "article"
'author-given "Sancho"
'author-family "McCann"
'title "My article"
'journal "A journal"
'volume "2"
'short-form "McCann"))))
(check-exn exn:fail? (λ () (validate-work-or-die (hash 'type "garbage"
'author-given "Sancho"
'author-family "McCann"
'title "My article"
'journal "A journal"
'volume "2"
'short-form "McCann")))))
(define/contract (validate-mandatory-elements type w mandatory-elements)
(valid-work-type? hash? (listof symbol?) . -> . void?)
(for-each
(λ (e)
(when (not (hash-ref w e))
(raise-user-error (format "~a is missing required field: ~a" type e)))) mandatory-elements))
(module+ test
(check-not-exn (λ () (validate-mandatory-elements "article" (hash 'key1 "value1" 'key2 "value2") '(key1 key2))))
(check-exn exn:fail? (λ () (validate-mandatory-elements "article" (hash 'key1 "value1" 'key2 #f) '(key1 key2))))
(check-exn exn:fail? (λ () (validate-mandatory-elements "article" (hash 'key1 "value1" 'key2 "value2") '(key1 key2 key3))))
)
(define (work-has-author-or-die w)
(when (not (or (and (hash-ref w 'author-given #f) (hash-ref w 'author-family #f)) (hash-ref w 'author-institutional #f)))
(raise-user-error "failed to specify an author of any kind for this work: " w)))
(define (validate-article w)
(validate-mandatory-elements "article" w '(title journal))
(work-has-author-or-die w))
(define (validate-chapter w)
(validate-mandatory-elements "chapter" w '(title in-book first-page))
(work-has-author-or-die w))
(define (validate-book w)
(validate-mandatory-elements "book" w '(title year)))
(define (validate-thesis w)
(validate-mandatory-elements "thesis" w '(title institution thesis-description year))
(work-has-author-or-die w))
(define (validate-proceedings w)
(validate-mandatory-elements "proceedings" w '(title proceedings year))
(work-has-author-or-die w))
(define (validate-unpublished w)
(validate-mandatory-elements "unpublished" w '(title year))
(work-has-author-or-die w))
(define (validate-bill w)
(validate-mandatory-elements "bill" w '(number title legislative-body year)))
(define (validate-statute w)
(validate-mandatory-elements "statute" w '(title volume year chapter)))
(define (validate-regulation w)
(validate-mandatory-elements "regulation" w '(title volume year)))
(define (validate-debate w)
(validate-mandatory-elements "debate" w '(jurisdiction legislative-body year))
; These next two elements must go together. They must either both be specified
; or both be unspecified.
(when (and (hash-ref w 'title) (not (hash-ref w 'reading)))
(raise-user-error "specified the title of a bill under debate without specifying which reading: " w))
(when (and (hash-ref w 'reading) (not (hash-ref w 'title)))
(raise-user-error "specified a reading of a bill without specifying the title of the bill: " w)))
(define (validate-magazine/news w)
(validate-mandatory-elements "magazine/news" w '(title)))
(define (validate-custom w)
(validate-mandatory-elements "custom" w '(custom-format)))
(define (validate-legal-case w)
(validate-mandatory-elements "legal-case" w '(title citation))
(when (and (hash-ref w 'cited-to) (not (string-contains? (hash-ref w 'citation) (hash-ref w 'cited-to))))
(raise-user-error "the cited-to helper information, if provided, must refer to the primary citation: " (hash-ref w 'citation)))
(when (and (year-is-necessary? (hash-ref w 'citation)) (not (hash-ref w 'year)))
(raise-user-error "Failed to declare year when year is not the first element of the first citation: " (hash-ref w 'citation))))
(define (validate-legal-case-US w)
(validate-mandatory-elements "legal-case-US" w '(title citation year)))
(define/contract (build-author-based-short-form author1 author2 author3)
(string? (or/c string? #f) (or/c string? #f) . -> . string?)
(apply string-append
`(,author1
,@(when-or-empty (and author2 (not author3)) `(" & " ,author2))
,@(when-or-empty (and author2 author3) `(", " ,author2))
,@(when-or-empty author3 `(" & " ,author3)))))
; "article" "chapter" "thesis" "proceedings" "unpublished" "debate" "book" "magazine/news"
(define/contract (default-short-form work)
(hash? . -> . txexpr-elements?)
(case (hash-ref work 'type)
[("legal-case" "legal-case-US" "statute" "regulation") `((em ,(hash-ref work 'title)))]
[("bill") `(,(string-append "Bill " (hash-ref work 'number)))]
[("article" "chapter" "thesis" "proceedings" "unpublished" "book")
(if (hash-ref work 'author-family)
`(,(build-author-based-short-form
(hash-ref work 'author-family)
(hash-ref work 'author2-family)
(hash-ref work 'author3-family)))
(raise-user-error "Failed to create default short-form for work." work))]
[("magazine/news")
(if (hash-ref work 'author-family)
`(,(build-author-based-short-form
(hash-ref work 'author-family)
(hash-ref work 'author2-family)
(hash-ref work 'author3-family)))
(merge-successive-strings (append '("“") (style-markedup-text (hash-ref work 'title)) '("”"))))]
[else (raise-user-error "Can't create default short-forms for works of this type." work)]))
(define/contract (default-short-form-undetermined? work)
(hash? . -> . boolean?)
(case (hash-ref work 'type)
[("legal-case" "legal-case-US" "statute" "regulation" "bill") #f]
[("article" "chapter" "thesis" "proceedings" "unpublished" "book") (not (hash-ref work 'author-family))]
[("magazine/news") (and (not (hash-ref work 'author-family)) (not (hash-ref work 'title)))]
[else #t]))
(module+ test
(test-begin
(declare-work #:type "book" #:author "Peyton Manning" #:title "How to throw a football" #:year "2012" #:id "manning")
(check-equal? (hash-ref (hash-ref work-metadata "manning") 'short-form) `("Manning"))
(declare-work #:type "magazine/news" #:title "title with some *italicized* portion" #:id "title-only-work")
(check-equal? (hash-ref (hash-ref work-metadata "title-only-work") 'short-form) `("“title with some " (em "italicized") " portion”"))))
; (check-equal? (default-short-form "book" "McCann" #f #f "Title") `("McCann"))
; (check-equal? (default-short-form "article" "McCann" "Lowe" #f "Title") `("McCann & Lowe"))
; (check-equal? (default-short-form "article" "McCann" "Lowe" "Muja" "Title") `("McCann, Lowe & Muja")))
(define/contract (work-has-short-form? work)
(hash? . -> . boolean?)
(hash-ref work 'short-form #f))
(define/contract (add-short-form-to-incomplete-work work)
((not/c work-has-short-form?) . -> . hash?)
; Copy the existing work structure but with a new short-form
(define complete-work (hash-copy work))
(hash-set! complete-work 'short-form (default-short-form work))
complete-work)
(define (declare-work #:type type
#:id id
#:title [title #f]
#:author [author #f] ; a shortcut for simple "author-given author-family" names --- incompatible with author-given / author-family
#:author-institutional [author-institutional #f] ; if the author is an institution rather than a person
#:author-given [author-given #f]
#:author-family [author-family #f]
#:author2-given [author2-given #f]
#:author2-family [author2-family #f]
#:author3-given [author3-given #f]
#:author3-family [author3-family #f]
#:editors? [editors? ""] ; will be treated as false unless an affirmative string is given
#:etal? [etal? ""] ; will be treated as false unless an affirmative string is given
#:in-book [in-book #f] ; needed for chapter citations
#:journal [journal #f]
#:edition [edition #f]
#:year [year #f] ; alias for "date" --- incompatible with date
#:date [date #f] ; alias for "year" --- incompatible with year
#:volume [volume #f]
#:publication [publication #f] ; for magazine/news
#:issue [issue #f]
#:citation [citation #f]
#:parallel-citation [parallel-citation #f]
#:jurisdiction [jurisdiction #f]
#:case-judge [case-judge #f]
#:institution [institution #f]
#:legislative-body [legislative-body #f]
#:number [number #f] ; for bills and some regulations
#:chapter [chapter #f] ; for statutes and some regulations
#:reading [reading #f] ; for legislative debates
#:bill-status [bill-status #f] ; a parenthetical at the end of bill's citation
#:eventual-statute [eventual-statute #f] ; additional detail for a bill that has passed
#:proceedings [proceedings #f]
#:publisher [publisher #f]
#:publisher-location [publisher-location #f]
#:thesis-description [thesis-description #f]
#:description [description #f]
#:comment-info [comment-info #f]
#:forthcoming [forthcoming #f]
#:pages [pages #f] ; will extract the first-page from this; incompatible with first-page
#:first-page [first-page #f]
#:url [url #f]
#:display-url? [display-url? #f]
#:online-type [online-description #f]
#:online-title [online-title #f]
#:custom-format [custom-format #f] ; only for type "custom"
#:short-form [short-form #f]
#:cited-to [cited-to #f])
(define cleaned-id (clean-param id))
(when (and author (or author-given author-family))
(raise-user-error "You used #:author and either #:author-given or #:author-family. #:author is a substitute for the latter when the name is simple." `(,author ,author-given ,author-family)))
(when (and author-institutional (or author author-given author-family))
(raise-user-error "You used #:author-institutional, which precludes use of the other author fields #:author, #:author-given, #:author-family." `(,author-institutional)))
(when (and year date)
(raise-user-error "You specified both a year and a date. Use only one of these." `(,year ,date ,title)))
(when (and pages first-page)
(raise-user-error "You specified both pages and first-page. Use only one of these." `(,pages ,first-page)))
(when (hash-has-key? work-metadata cleaned-id) (raise-user-error "duplicate id" cleaned-id))
(define incomplete-work
(hash 'type type
'id cleaned-id
'title (clean-param title)
'author-institutional (clean-param author-institutional)
'author-given (if author (get-given-from-author author) (clean-param author-given))
'author-family (if author (get-family-from-author author) (clean-param author-family))
'author2-given (clean-param author2-given)
'author2-family (clean-param author2-family)
'author3-given (clean-param author3-given)
'author3-family (clean-param author3-family)
'editors? (clean-param editors?)
'etal? (clean-param etal?)
'in-book (clean-param in-book)
'journal (clean-param journal)
'edition (clean-param edition)
'publication (clean-param publication)
'year (if year year date)
'volume volume
'issue issue
'citation (clean-param citation)
'parallel-citation (clean-param parallel-citation)
'jurisdiction (clean-param jurisdiction)
'case-judge (clean-param case-judge)
'institution (clean-param institution)
'legislative-body (clean-param legislative-body)
'number (clean-param number)
'chapter (clean-param chapter)
'bill-status (clean-param bill-status)
'eventual-statute (clean-param eventual-statute)
'reading (clean-param reading)
'proceedings (clean-param proceedings)
'publisher (clean-param publisher)
'publisher-location (clean-param publisher-location)
'thesis-description (clean-param thesis-description)
'description (clean-param description)
'comment-info (clean-param comment-info)
'forthcoming forthcoming
'first-page (if pages (extract-first-page pages) first-page)
'url url
'display-url? display-url?
'online-description (clean-param online-description)
'online-title (clean-param online-title)
'custom-format (clean-param custom-format)
'short-form (if short-form
(style-markedup-text (clean-param short-form))
#f)
'cited-to cited-to))
(define this-work
(if (hash-ref incomplete-work 'short-form)
incomplete-work
(add-short-form-to-incomplete-work incomplete-work)))
(validate-work-or-die this-work)
(hash-set! work-metadata cleaned-id this-work))
; Just forward all arguments to declare-work, but this form does not accept
; an id. It will return a txexpr to be rendered in-place.
; TODO: Find a way to programmatically re-use these arguments.
(define (format-work #:type type
#:title [title #f]
#:author [author #f] ; a shortcut for simple "author-given author-family" names --- incompatible with author-given / author-family
#:author-institutional [author-institutional #f] ; used for institutional authors rather than people
#:author-given [author-given #f]
#:author-family [author-family #f]
#:author2-given [author2-given #f]
#:author2-family [author2-family #f]
#:author3-given [author3-given #f]
#:author3-family [author3-family #f]
#:editors? [editors? ""]
#:etal? [etal? ""]
#:in-book [in-book #f]
#:journal [journal #f]
#:edition [edition #f]
#:year [year #f] ; alias for "date" --- incompatible with date
#:date [date #f] ; alias for "year" --- incompatible with year
#:volume [volume #f]
#:publication [publication #f] ; for magazine/news
#:issue [issue #f]
#:citation [citation #f]
#:parallel-citation [parallel-citation #f]
#:jurisdiction [jurisdiction #f]
#:case-judge [case-judge #f]
#:institution [institution #f]
#:legislative-body [legislative-body #f]
#:number [number #f] ; for bills
#:chapter [chapter #f] ; for statutes
#:reading [reading #f] ; for legislative debates
#:bill-status [bill-status #f] ; a parenthetical at the end of bill's citation
#:eventual-statute [eventual-statute #f] ; additional detail for a bill that has passed
#:proceedings [proceedings #f]
#:publisher [publisher #f]
#:publisher-location [publisher-location #f]
#:thesis-description [thesis-description #f]
#:description [description #f]
#:comment-info [comment-info #f]
#:forthcoming [forthcoming #f]
#:pages [pages #f] ; will extract the first-page from this; incompatible with first-page
#:first-page [first-page #f]
#:url [url #f]
#:display-url? [display-url? #f]
#:online-type [online-description #f]
#:online-title [online-title #f]
#:custom-format [custom-format #f]
#:short-form [short-form #f])
(define id (format "unidentified-work-~a" unidentified-work-count))
(set! unidentified-work-count (+ 1 unidentified-work-count))
(declare-work #:type type
#:id id
#:title title
#:author author
#:author-institutional author-institutional
#:author-given author-given
#:author-family author-family
#:author2-given author2-given
#:author2-family author2-family
#:author3-given author3-given
#:author3-family author3-family
#:editors? editors?
#:etal? etal?
#:in-book in-book
#:journal journal
#:edition edition
#:year year
#:date date
#:volume volume
#:publication publication
#:issue issue
#:citation citation
#:parallel-citation parallel-citation
#:jurisdiction jurisdiction
#:case-judge case-judge
#:institution institution
#:legislative-body legislative-body
#:number number
#:chapter chapter
#:reading reading
#:bill-status bill-status
#:eventual-statute eventual-statute
#:proceedings proceedings
#:publisher publisher
#:publisher-location publisher-location
#:thesis-description thesis-description
#:description description
#:comment-info comment-info
#:forthcoming forthcoming
#:pages pages
#:first-page first-page
#:url url
#:display-url? display-url?
#:online-type online-description
#:online-title online-title
#:custom-format custom-format
#:short-form id) ; short form will not be used
(cite id))
(define/contract (style-markedup-text markedup-text)
(string? . -> . txexpr-elements?)
(define italic-range (regexp-match-positions #rx"\\*.*?\\*" markedup-text))
(if italic-range
(let* ([before (substring markedup-text 0 (car (car italic-range)))]
[special-content (substring markedup-text (+ (car (car italic-range)) 1) (- (cdr (car italic-range)) 1))]
[after (substring markedup-text (cdr (car italic-range)))])
`(,@(when-or-empty (non-empty-string? before) `(,before))
(em ,special-content)
,@(when-or-empty (non-empty-string? after) `(,@(style-markedup-text after)))))
`(,markedup-text)))
(module+ test
(check-equal? (style-markedup-text "title") '("title"))
(check-equal? (style-markedup-text "title *with italics*") '("title " (em "with italics")))
(check-equal? (style-markedup-text "*italics* at start of title") '((em "italics") " at start of title"))
(check-equal? (style-markedup-text "*entire title italics*") '((em "entire title italics")))
(check-equal? (style-markedup-text "multiple *italics* sections *in* title") '("multiple " (em "italics") " sections " (em "in") " title"))
)
(define/contract (cite-ibid id #:pinpoint [pinpoint #f] #:chapter-first-page [chapter-first-page #f]
#:parenthetical [parenthetical #f] #:judge [judge #f] #:speaker [speaker #f] #:signal [signal #f] #:terminal [terminal "."])
(((and/c string? declared-id?)) (#:pinpoint (or/c string? #f) #:chapter-first-page (or/c string? #f) #:parenthetical (or/c string? #f)
#:judge (or/c string? #f) #:speaker (or/c string? #f)
#:signal (or/c string? #f) #:terminal string?) . ->* . txexpr?)
(define c-pinpoint (clean-param pinpoint))
(define c-chapter-first-page (clean-param chapter-first-page))
(define c-parenthetical (clean-param parenthetical))
(define c-judge (clean-param judge))
(define c-speaker (clean-param speaker))
(define c-signal (clean-param signal))
(define w (hash-ref work-metadata (clean-param id)))
`(span [[class "bibliography-entry"] [data-citation-id ,(clean-param id)]]
,@(merge-successive-strings
`(
,@(when-or-empty c-signal `(,c-signal " "))
,(if c-signal `(em "ibid") `(em "Ibid"))
,@(when-or-empty c-chapter-first-page `(", " ,c-chapter-first-page))
,@(when-or-empty c-parenthetical `(" (" ,c-parenthetical))
,@(when-or-empty c-pinpoint `(,(normalize-pinpoint c-pinpoint)))
,@(when-or-empty c-judge `(", " ,c-judge))
,@(when-or-empty c-parenthetical '(")"))
,@(when-or-empty c-speaker `(" (" ,c-speaker ")")) ; Only relevant for debates (TODO: consider specializing back-reference forms).
,terminal))))
(module+ test
(test-begin
(declare-work #:id "persons" #:type "legal-case"
#:title "Edwards v Canada (AG)" #:year "1929" #:citation "[1930] AC 124"
#:parallel-citation "1929 UKPC 86" #:short-form "*Persons Case*")
(check-equal? (get-elements (cite-ibid "persons"))
`((em "Ibid") "."))))
(define/contract (cite-supra id back-ref #:pinpoint [pinpoint #f] #:chapter-first-page [chapter-first-page #f] #:parenthetical [parenthetical #f]
#:judge [judge #f] #:speaker [speaker #f] #:signal [signal #f] #:terminal [terminal "."])
(((and/c string? declared-id?) exact-nonnegative-integer?) (#:pinpoint (or/c string? #f) #:chapter-first-page (or/c string? #f) #:parenthetical (or/c string? #f)
#:judge (or/c string? #f) #:speaker (or/c string? #f)
#:signal (or/c string? #f) #:terminal string?) . ->* . txexpr?)
(define c-pinpoint (clean-param pinpoint))
(define c-chapter-first-page (clean-param chapter-first-page))
(define c-parenthetical (clean-param parenthetical))
(define c-judge (clean-param judge))
(define c-speaker (clean-param speaker))
(define c-signal (clean-param signal))
(define w (hash-ref work-metadata (clean-param id)))
`(span [[class "bibliography-entry"] [data-citation-id ,(clean-param id)]]
,@(merge-successive-strings `(
,@(when-or-empty c-signal `(,c-signal " "))
,@(if (list? (hash-ref w 'short-form)) (hash-ref w 'short-form) `(,(hash-ref w 'short-form))) ", "
(em "supra") ,(format " note ~a" back-ref)
,@(when-or-empty c-chapter-first-page `(", " ,c-chapter-first-page))
,@(when-or-empty c-parenthetical `(" (" ,c-parenthetical))
,@(when-or-empty c-pinpoint `(,(normalize-pinpoint c-pinpoint)))
,@(when-or-empty c-judge `(", " ,c-judge))
,@(when-or-empty c-parenthetical '(")"))
,@(when-or-empty c-speaker `(" (" ,c-speaker ")"))
,terminal))))
(module+ test
(test-begin
(declare-work #:id "secession" #:type "legal-case"
#:title "Reference re Secession of Quebec" #:citation "[1998] 2 SCR 217"
#:short-form "*Secession Reference*")
(check-equal? (get-elements (cite-supra "secession" 2 #:pinpoint "219"))
`((em "Secession Reference") ", " (em "supra") " note 2 at 219."))
(declare-work #:id "BC PPPA" #:type "bill" #:number "2"
#:title "Protection of Public Participation Act" #:legislative-body "4th Sess, 41st Leg, British Columbia"
#:year "2019" #:short-form "BC *PPPA*")
(check-equal? (get-elements (cite-supra "BC PPPA" 1))
`("BC " (em "PPPA") ", " (em "supra") " note 1."))))
; Renders a full note-form of the work, which will possibly be replaced
; later by an ibid or supra if necessary.
(define/contract (cite id #:pinpoint [pinpoint #f] #:parenthetical [parenthetical #f] #:judge [judge #f] #:speaker [speaker #f]
#:signal [signal #f] #:terminal [terminal "."] #:format-authors-for-bibliography [bib-authors #f])
(((and/c string? declared-id?)) (#:pinpoint (or/c string? #f) #:parenthetical (or/c string? #f)
#:judge (or/c string? #f) #:speaker (or/c string? #f)
#:signal (or/c string? #f) #:terminal string? #:format-authors-for-bibliography boolean?) . ->* . txexpr?)
(define c-pinpoint (clean-param pinpoint))
(define c-parenthetical (clean-param parenthetical))
(define c-judge (clean-param judge))
(define c-speaker (clean-param speaker))
(define c-signal (clean-param signal))
(define w (hash-ref work-metadata (clean-param id)))
`(span [[class "bibliography-entry full-form-citation"]
[data-citation-id ,(clean-param id)]
[data-citation-pinpoint ,(if c-pinpoint c-pinpoint "false")]
[data-citation-parenthetical ,(if c-parenthetical c-parenthetical "false")]
[data-citation-judge ,(if c-judge c-judge "false")]
[data-citation-speaker ,(if c-speaker c-speaker "false")]
[data-citation-signal ,(if c-signal c-signal "false")]
[data-citation-terminal ,terminal]
]
,@(merge-successive-strings
`(
,@(when-or-empty c-signal `(,(format "~a " c-signal)))
,@(case (hash-ref w 'type)
[("article") (render-article-elements w c-pinpoint c-parenthetical bib-authors)]
[("chapter") (render-chapter-elements w c-pinpoint c-parenthetical bib-authors)]
[("book") (render-book-elements w c-pinpoint c-parenthetical bib-authors)]
[("thesis") (render-thesis-elements w c-pinpoint c-parenthetical bib-authors)]
[("proceedings") (render-proceedings-elements w c-pinpoint c-parenthetical bib-authors)]
[("unpublished") (render-unpublished-elements w c-pinpoint c-parenthetical bib-authors)]
[("legal-case") (render-legal-case-elements w c-pinpoint c-parenthetical c-judge)]
[("legal-case-US") (render-legal-case-US-elements w c-pinpoint c-parenthetical c-judge)]
[("bill") (render-bill-elements w c-pinpoint c-parenthetical)]
[("statute") (render-statute-elements w c-pinpoint c-parenthetical)]
[("regulation") (render-regulation-elements w c-pinpoint c-parenthetical)]
[("debate") (render-debate-elements w c-pinpoint c-speaker)]
[("magazine/news") (render-magazine/news-elements w c-pinpoint c-parenthetical bib-authors)]
[("custom") (render-custom-elements w c-pinpoint c-parenthetical c-judge)]
[else (raise-user-error "No implementation for rendering this type of citation: " (hash-ref w 'type))])
,terminal))))
(define/contract (bib-entry id)
((and/c string? declared-id?) . -> . txexpr?)
(cite id #:format-authors-for-bibliography #t))
(define/contract (bib-sort-value id)
((and/c string? declared-id?) . -> . string?)
(define w (hash-ref work-metadata id))
(define type (hash-ref w 'type))
(case type
[("article" "chapter" "book" "thesis" "proceedings" "unpublished") (format-authors w #t)]
[("magazine/news") (if (or (hash-ref w 'author-institutional #f) (hash-ref w 'author-family))
(format-authors w #t)
(hash-ref w 'title))]
[("debate") (hash-ref w 'proceedings)]
[("custom") (hash-ref w 'custom-format)]
[else (hash-ref w 'title)]))
(define/contract (short-form id)
((and/c string? declared-id?) . -> . txexpr-elements?)
(hash-ref (get-work-by-id id) 'short-form))
(module+ test
(test-begin
(declare-work #:id "jordan" #:type "legal-case" #:title "R v Jordan" #:short-form "*Jordan*" #:citation "2016 SCC 27")
(check-equal? (short-form "jordan") '((em "Jordan")))))
; TODO: Make this the behaviour instead. Legal cases should default to italics for short form if there is no
; formatting markup provided.
; (declare-work #:id "jordan" #:type "legal-case" #:title "R v Jordan" #:short-form "Jordan" #:citation "2016 SCC 27")
; (check-equal? (short-form "jordan") '((em "Jordan")))))
(define/contract (format-authors w [bibliography-formatted? #f])
((hash?) (boolean?) . ->* . string?)
(define multiple-authors? (hash-ref w 'author2-given #f))
(string-append
(if (hash-ref w 'author-institutional #f)
(hash-ref w 'author-institutional #f)
(string-append
(if bibliography-formatted? (hash-ref w 'author-family) (hash-ref w 'author-given))
(if bibliography-formatted? ", " " ")
(if bibliography-formatted? (hash-ref w 'author-given) (hash-ref w 'author-family))))
(if (and (hash-ref w 'author2-family #f) (not (hash-ref w 'author3-family #f))) " & " "")
(if (and (hash-ref w 'author2-family #f) (hash-ref w 'author3-family #f)) ", " "")
(if (hash-ref w 'author2-given #f) (hash-ref w 'author2-given #f) "")
(if (hash-ref w 'author2-family #f) (format " ~a" (hash-ref w 'author2-family #f)) "")
(if (hash-ref w 'author3-family #f) " & " "")
(if (hash-ref w 'author3-given #f) (hash-ref w 'author3-given #f) "")
(if (hash-ref w 'author3-family #f) (format " ~a" (hash-ref w 'author3-family #f)) "")
(if (string-is-affirmative? (hash-ref w 'etal? "")) " et al" "")
(if (string-is-affirmative? (hash-ref w 'editors? "")) ", ed" "")
(if (and (string-is-affirmative? (hash-ref w 'editors? "")) multiple-authors?) "s" "")))
(module+ test
(check-equal? (format-authors (hash 'author-given "Sancho" 'author-family "McCann")) "Sancho McCann")
(check-equal? (format-authors (hash 'author-given "Sancho" 'author-family "McCann"
'author2-given "David G" 'author2-family "Lowe")) "Sancho McCann & David G Lowe")
(check-equal? (format-authors (hash 'author-given "Natasha" 'author-family "Novac"
'author2-given "Bailey" 'author2-family "Fox"
'author3-given "Nora" 'author3-family "Parker")) "Natasha Novac, Bailey Fox & Nora Parker")
(check-equal? (format-authors (hash 'author-given "Sancho" 'author-family "McCann" 'etal? "yes")) "Sancho McCann et al")
(check-equal? (format-authors (hash 'author-given "Colleen M" 'author-family "Flood"
'author2-given "Lorne" 'author2-family "Sossin" 'editors? "yes"))
"Colleen M Flood & Lorne Sossin, eds")
(check-equal? (format-authors (hash 'author-institutional "UNESCO")) "UNESCO"))
(define/contract (format-url url)
(string? . -> . txexpr-elements?)
`(,(string-append
", online"
(if (or (string-contains? url "youtu.be")
(string-contains? url "youtube.com"))
" (video)"
"")
": <")
(a [[href ,url]] ,(strip-http/https-protocol url))
">"))
(module+ test
(check-equal? (format-url "https://youtu.be/ndLcvzA6S3I") '(", online (video): <" (a [[href "https://youtu.be/ndLcvzA6S3I"]] "youtu.be/ndLcvzA6S3I") ">")))
(define (short-form-pre-placeholder id)
`(span [[data-short-form-pre-placeholder ,id]]))
; -----------------------------------------------------------------------------------
; These are all the functions that do the citation layout.
(define/contract (render-article-elements w pinpoint parenthetical bib-authors)
(hash? (or/c string? #f) (or/c string? #f) boolean? . -> . txexpr-elements?)
(define title-elements (style-markedup-text (hash-ref w 'title)))
(define fragmented
`(,(format-authors w bib-authors)
", “"
,@(if (hash-ref w 'url) `((a [[href ,(hash-ref w 'url)]] ,@title-elements)) title-elements)
"”"
,@(when-or-empty (hash-ref w 'comment-info) `(", " ,(hash-ref w 'comment-info) ", "))
,@(when-or-empty (hash-ref w 'year) `(" (" ,(hash-ref w 'year) ")"))
,@(when-or-empty (hash-ref w 'volume) `(" " ,(hash-ref w 'volume)))
,@(when-or-empty (hash-ref w 'issue) `(":" ,(hash-ref w 'issue)))
" "
,(hash-ref w 'journal)
,@(when-or-empty (hash-ref w 'forthcoming) `(" [forthcoming in " ,(hash-ref w 'forthcoming) "]"))
,@(when-or-empty (hash-ref w 'first-page) `(" " ,(hash-ref w 'first-page)))
,@(when-or-empty (and (not parenthetical) pinpoint) `(,(normalize-pinpoint pinpoint)))
,@(when-or-empty (and (hash-ref w 'display-url?) (hash-ref w 'url)) `(,@(format-url (hash-ref w 'url))))
,(short-form-pre-placeholder (hash-ref w 'id))
,@(when-or-empty parenthetical `(" (" ,parenthetical))
,@(when-or-empty (and parenthetical pinpoint) `(,(normalize-pinpoint pinpoint)))
,@(when-or-empty parenthetical '(")"))))
(merge-successive-strings fragmented))
(module+ test
(test-begin
(declare-work #:id "id1" #:type "article" #:author "Sancho McCann" #:title "Title" #:journal "Journal" #:volume "1" #:year "2018" #:short-form "McCann, \"Title\"")
(check-equal? (get-elements (cite "id1")) '("Sancho McCann, “Title” (2018) 1 Journal" (span [[data-short-form-pre-placeholder "id1"]]) "."))
(declare-work #:id "id2" #:type "article" #:author "Sancho McCann" #:title "Title 2" #:journal "Journal" #:volume "1" #:issue "2" #:pages "501--503" #:year "2018" #:short-form "McCann, \"Title 2\"")
(check-equal? (get-elements (cite "id2")) '("Sancho McCann, “Title 2” (2018) 1:2 Journal 501" (span [[data-short-form-pre-placeholder "id2"]]) "."))
(declare-work #:id "kamara" #:type "article" #:author "Alvin Kamara" #:title "Title" #:journal "Journal" #:volume "1" #:year "2018" #:url "https://www.nfl.com")
(check-equal? (get-elements (cite "kamara")) '("Alvin Kamara, “" (a [[href "https://www.nfl.com"]] "Title") "” (2018) 1 Journal" (span [[data-short-form-pre-placeholder "kamara"]]) "."))
(declare-work #:id "lorde" #:type "article" #:author "Audrey Lorde" #:title "Title" #:journal "Journal" #:volume "1" #:year "2018" #:url "https://www.nfl.com" #:display-url? #t)
(check-equal? (get-elements (cite "lorde")) '("Audrey Lorde, “" (a [[href "https://www.nfl.com"]] "Title") "” (2018) 1 Journal, online: <" (a [[href "https://www.nfl.com"]] "www.nfl.com") ">" (span [[data-short-form-pre-placeholder "lorde"]]) "."))
(declare-work #:id "hohfeld" #:type "article" #:author-given "Wesley Newcomb" #:author-family "Hohfeld"
#:title "The Relations between Equity and Law" #:year "1913" #:journal "Mich L Rev" #:volume "11" #:issue "8" #:first-page "537")
(check-equal? (get-elements (cite "hohfeld"))
'("Wesley Newcomb Hohfeld, “The Relations between Equity and Law” (1913) 11:8 Mich L Rev 537" (span [[data-short-form-pre-placeholder "hohfeld"]]) "."))
(check-equal? (get-elements (cite "hohfeld" #:pinpoint "page 538"))
'("Wesley Newcomb Hohfeld, “The Relations between Equity and Law” (1913) 11:8 Mich L Rev 537 at 538" (span [[data-short-form-pre-placeholder "hohfeld"]]) "."))
(check-equal? (get-elements (cite "hohfeld" #:pinpoint "page 538" #:parenthetical "on the history of the Chancery Courts in England"))
'("Wesley Newcomb Hohfeld, “The Relations between Equity and Law” (1913) 11:8 Mich L Rev 537" (span [[data-short-form-pre-placeholder "hohfeld"]]) " (on the history of the Chancery Courts in England at 538)."))))
(define/contract (render-chapter-elements w pinpoint parenthetical bib-authors)
(hash? (or/c string? #f) (or/c string? #f) boolean? . -> . txexpr-elements?)
(define title-elements (style-markedup-text (hash-ref w 'title)))
(define fragmented
`(
,(format-authors w bib-authors)
", “"
,@(if (hash-ref w 'url) `((a [[href ,(hash-ref w 'url)]] ,@title-elements)) title-elements)
"”"
,(short-form-pre-placeholder (hash-ref w 'id))
" in "
(span [[class "bibliography-entry full-form-citation"]
[data-citation-id ,(hash-ref w 'in-book)]
[data-citation-pinpoint "false"]
[data-citation-chapter-first-page ,(hash-ref w 'first-page)]
[data-citation-parenthetical "false"]
[data-citation-judge "false"]
[data-citation-speaker "false"]
[data-citation-signal "false"]
[data-citation-terminal ""]
]
,@(render-book-elements (get-work-by-id (hash-ref w 'in-book)) #f #f #f (hash-ref w 'first-page)))
,@(when-or-empty pinpoint `(,(normalize-pinpoint pinpoint)))
))
(merge-successive-strings fragmented))
(module+ test
(test-begin
(declare-work #:id "Flood" #:type "book" #:title "Administrative Law in Context"