Index: tags-html.rkt
==================================================================
--- tags-html.rkt
+++ tags-html.rkt
@@ -11,10 +11,11 @@
racket/draw
racket/class
pollen/decode
pollen/tag
pollen/setup
+ pollen/core
net/uri-codec
txexpr
"dust.rkt")
(provide html-fn
@@ -226,24 +227,28 @@
block-xpr))
;; Links
;;
;; Private use:
-(define link-urls (make-hash))
+(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)
- (hash-set! link-urls (format "~a" 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 link-urls url-ref #f)
+ [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
@@ -257,39 +262,47 @@
,@(rest elems))]))
;; Footnotes
;;
;; Private use:
-(define fn-names null)
-(define fn-definitions (make-hash))
+(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)))
- (set! fn-names (cons name fn-names))
+ (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) fn-names))]
+ [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 fn-names)) name))]
+ [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)
- (hash-set! fn-definitions (format "~a" (first elems)) (rest 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 fn-names)))])
- (let* ([definition-text (or (hash-ref fn-definitions fn-name #f)
+ (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) fn-names)]
+ [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))))