Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion scribble-doc/scriblib/scribblings/footnote.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,37 @@

@defmodule[scriblib/footnote]

@defproc[(note [pre-content pre-content?] ...) element?]{
@defparam[note-number number (or/c integer? #f 'next)]{
This parameter controls the number of footnotes in the HTML renderer.
See @racket[note] for how it is interpreted.

To enable footnote numbers in HTML,
add @racket[#:number 'next] to your first call to @racket[note]
(you can also add it to subsequent calls, but that is not necessary);
or set this parameter to either 1 or @racket['next].
To disable footnote numbers again in HTML,
set this parameter back to @racket[#f] (the default).

@history[#:added "1.62"]
}

@defproc[(note [#:number number (or/c integer? boolean?) (note-number)]
[pre-content pre-content?] ...) element?]{

Creates a margin note for HTML and a footnote for Latex/PDF output.

If rendering HTML, then the number parameter is used, which default to @racket[(note-number)].
If it is @racket[#f] then no number is used (default / legacy behavior).
If it is @racket['next] and @racket[(note-number)] is an integer,
then the latter value is used.
If it is @racket['next] and @racket[(note-number)] is not integer,
then the value 1 will be used instead.
If it is an integer, then its value is used.
If an integer value is used, then @racket[(note-number)] is set to the next integer.

@history[#:changed "1.63" @elem{Added @racket[#:number].}]
}

To produce a numbered note for HTML (which can useful if a CSS
specialization changes how ``margin notes'' are rendered), use
@racket[define-footnote] with @racket[#:margin], instead.
Expand Down
2 changes: 1 addition & 1 deletion scribble-lib/info.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

(define pkg-authors '(mflatt eli))

(define version "1.62")
(define version "1.63")

(define license
'((Apache-2.0 OR MIT)
Expand Down
44 changes: 39 additions & 5 deletions scribble-lib/scriblib/footnote.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

(require (for-syntax racket/base)
scribble/core
(only-in scribble/base superscript)
(only-in scriblib/render-cond cond-element)
scribble/decode
scribble/html-properties
scribble/latex-properties
Expand All @@ -11,6 +13,7 @@
"private/counter.rkt")

(provide note
note-number
define-footnote)

(define footnote-style-extras
Expand All @@ -24,12 +27,43 @@
(define note-box-style (make-style "NoteBox" footnote-style-extras))
(define note-content-style (make-style "NoteContent" footnote-style-extras))

(define (note . text)
(make-element
note-box-style
(make-element note-content-style
(decode-content text))))
(define note-number (make-parameter #f))

;; TODO: move this utility function somewhere it can be exported from
(define (xexpr-element xexpr)
(make-element (make-style #f (list (xexpr-property xexpr ""))) '()))

(define (note #:number [number (note-number)] . text)
(define (no-number)
(make-element
note-box-style
(make-element note-content-style
(decode-content text))))
(cond-element
[html
(if number
(let* ([n (if (integer? number)
number
(let ([nn (note-number)])
(if (integer? nn) nn 1)))]
[a (lambda (x y)
(xexpr-element `[a ([name ,(format "__footnote_~a_~a__" x n)]
[href ,(format "#__footnote_~a_~a__" y n)])
[sup () ,(format "~a" n)]]))])
(note-number (+ n 1))
(make-element plain
(list
(a "source" "target")
(make-element
note-box-style
(make-element note-content-style
(list
(a "target" "source")
": "
(decode-content text)))))))
(no-number))]
[else
(no-number)]))

(define footnote-style (make-style "Footnote" footnote-style-extras))
(define footnote-ref-style (make-style "FootnoteRef" footnote-style-extras))
Expand Down