◊(Local Yarn Code "Check-in [8b3cc120]")

Overview
Comment:Explicitly preserve footnote and link state per page (Pollen no longer guarantees this)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8b3cc120639128f43ffbaf2cd14c1f27607dfa7f94a517dd3efc80aad01eb43f
User & Date: joel on 2020-05-11 01:58:14
Other Links: manifest | tags
Context
2020-05-11
01:59
No empty “Further Notes” sections check-in: 542a013e user: joel tags: trunk
01:58
Explicitly preserve footnote and link state per page (Pollen no longer guarantees this) check-in: 8b3cc120 user: joel tags: trunk
01:56
Make most article columns nullable check-in: f59aba82 user: joel tags: trunk
Changes

Modified tags-html.rkt from [3c9c01a9] to [88b1006b].

9
10
11
12
13
14
15

16
17
18
19
20
21
22
...
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
...
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
(require racket/list
         racket/function
         racket/draw
         racket/class
         pollen/decode
         pollen/tag
         pollen/setup

         net/uri-codec
         txexpr
         "dust.rkt")

(provide html-fn
         html-fndef)

................................................................................
           (is-newthought? (first (get-elements block-xpr))))
      (attr-set block-xpr 'class "pause-before")
      block-xpr))

;; Links
;;
;; Private use:
(define link-urls (make-hash))

;; Provided tag functions:
(define (html-link . args)
  `(link& [[ref ,(format "~a" (first args))]] ,@(rest args)))

(define (html-url ref url)


  (hash-set! link-urls (format "~a" ref) url) "")

;; Private use (by html-root):
(define (decode-link-urls tx)


  (cond [(eq? (get-tag tx) 'link&)
         (let* ([url-ref (attr-ref tx 'ref)]
                [url (or (hash-ref link-urls url-ref #f)
                         (format "Missing reference: ~a" url-ref))])
           `(a [[href ,url]] ,@(get-elements tx)))]
        [else tx]))

;; Fast link to another article
(define html-xref
  (case-lambda
................................................................................
    [elems `(a [[href ,(format "~aarticles/~a.html" web-root (first elems))]
                [class "xref"]]
               ,@(rest elems))]))

;; Footnotes
;;
;; Private use:
(define fn-names null)
(define fn-definitions (make-hash))
(define (fn-id x) (here-id (string-append x "_fn")))
(define (fndef-id x) (here-id (string-append x "_fndef")))

;; Provided footnote tag functions:
(define (html-fn . args)
  (define name (format "~a" (first args)))
  (set! fn-names (cons name fn-names))



  (let* ([def-anchorlink (string-append "#" (fndef-id name))]
         [nth-ref        (number->string (count (curry string=? name) fn-names))]
         [ref-id         (string-append (fn-id name) nth-ref)]
         [fn-number      (+ 1 (index-of (remove-duplicates (reverse fn-names)) name))]
         [ref-text       (format "(~a)" fn-number)])
    (cond [(empty? (rest args)) `(sup (a [[href ,def-anchorlink] [id ,ref-id]] ,ref-text))]
          [else `(span [[class "links-footnote"] [id ,ref-id]]
                       ,@(rest args)
                       (sup (a [[href ,def-anchorlink]] ,ref-text)))])))

(define (html-fndef . elems)


  (hash-set! fn-definitions (format "~a" (first elems)) (rest elems)))

;; Private use (by html-root)
(define (html-footnote-block)



  (define note-items
    (for/list ([fn-name (in-list (remove-duplicates (reverse fn-names)))])
      (let* ([definition-text (or (hash-ref fn-definitions fn-name #f)
                                  '((i "Missing footnote definition!")))]
             [backref-count (count (curry string=? fn-name) fn-names)]
             [backrefs (for/list ([fnref-num (in-range backref-count)])
                         `(a [[href ,(string-append "#"
                                                    (fn-id fn-name)
                                                    (format "~a" (+ 1 fnref-num)))]] "↩"))])
        `(li [[id ,(fndef-id fn-name)]] ,@definition-text ,@backrefs))))
  (cond [(null? note-items) ""]
        [else `(section ((class "footnotes")) (hr) (ol ,@note-items))]))

(define (html-note-with-srcline attrs elems)
  (txexpr 'note attrs (decode-hardwrapped-paragraphs elems)))







>







 







|






>
>
|



>
>


|







 







|
|






|
>
>
>

|

|







>
>
|



>
>
>

|
|

|










9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
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
...
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
(require racket/list
         racket/function
         racket/draw
         racket/class
         pollen/decode
         pollen/tag
         pollen/setup
         pollen/core
         net/uri-codec
         txexpr
         "dust.rkt")

(provide html-fn
         html-fndef)

................................................................................
           (is-newthought? (first (get-elements block-xpr))))
      (attr-set block-xpr 'class "pause-before")
      block-xpr))

;; Links
;;
;; Private use:
(define all-link-urls (make-hash))

;; Provided tag functions:
(define (html-link . args)
  `(link& [[ref ,(format "~a" (first args))]] ,@(rest args)))

(define (html-url ref url)
  (define page-path (hash-ref (current-metas) 'here-path))
  (define page-link-urls (hash-ref! all-link-urls page-path make-hash))
  (hash-set! page-link-urls (format "~a" ref) url) "")

;; Private use (by html-root):
(define (decode-link-urls tx)
  (define page-path (hash-ref (current-metas) 'here-path))
  (define page-link-urls (hash-ref! all-link-urls page-path make-hash))
  (cond [(eq? (get-tag tx) 'link&)
         (let* ([url-ref (attr-ref tx 'ref)]
                [url (or (hash-ref page-link-urls url-ref #f)
                         (format "Missing reference: ~a" url-ref))])
           `(a [[href ,url]] ,@(get-elements tx)))]
        [else tx]))

;; Fast link to another article
(define html-xref
  (case-lambda
................................................................................
    [elems `(a [[href ,(format "~aarticles/~a.html" web-root (first elems))]
                [class "xref"]]
               ,@(rest elems))]))

;; Footnotes
;;
;; Private use:
(define all-fn-names (make-hash))
(define all-fn-definitions (make-hash))
(define (fn-id x) (here-id (string-append x "_fn")))
(define (fndef-id x) (here-id (string-append x "_fndef")))

;; Provided footnote tag functions:
(define (html-fn . args)
  (define name (format "~a" (first args)))
  (define page-path (hash-ref (current-metas) 'here-path))
  (define page-fn-names (cons name (hash-ref! all-fn-names page-path '())))
  (hash-set! all-fn-names page-path page-fn-names)
  
  (let* ([def-anchorlink (string-append "#" (fndef-id name))]
         [nth-ref        (number->string (count (curry string=? name) page-fn-names))]
         [ref-id         (string-append (fn-id name) nth-ref)]
         [fn-number      (+ 1 (index-of (remove-duplicates (reverse page-fn-names)) name))]
         [ref-text       (format "(~a)" fn-number)])
    (cond [(empty? (rest args)) `(sup (a [[href ,def-anchorlink] [id ,ref-id]] ,ref-text))]
          [else `(span [[class "links-footnote"] [id ,ref-id]]
                       ,@(rest args)
                       (sup (a [[href ,def-anchorlink]] ,ref-text)))])))

(define (html-fndef . elems)
  (define page-path (hash-ref (current-metas) 'here-path))
  (define page-fn-defs (hash-ref! all-fn-definitions page-path make-hash))
  (hash-set! page-fn-defs (format "~a" (first elems)) (rest elems)))

;; Private use (by html-root)
(define (html-footnote-block)
  (define page-path (hash-ref (current-metas) 'here-path))
  (define page-fn-names (hash-ref! all-fn-names page-path '()))
  (define page-fn-defs (hash-ref! all-fn-definitions page-path (make-hash)))
  (define note-items
    (for/list ([fn-name (in-list (remove-duplicates (reverse page-fn-names)))])
      (let* ([definition-text (or (hash-ref page-fn-defs fn-name #f)
                                  '((i "Missing footnote definition!")))]
             [backref-count (count (curry string=? fn-name) page-fn-names)]
             [backrefs (for/list ([fnref-num (in-range backref-count)])
                         `(a [[href ,(string-append "#"
                                                    (fn-id fn-name)
                                                    (format "~a" (+ 1 fnref-num)))]] "↩"))])
        `(li [[id ,(fndef-id fn-name)]] ,@definition-text ,@backrefs))))
  (cond [(null? note-items) ""]
        [else `(section ((class "footnotes")) (hr) (ol ,@note-items))]))

(define (html-note-with-srcline attrs elems)
  (txexpr 'note attrs (decode-hardwrapped-paragraphs elems)))