diff --git a/pkgs/scribble-pkgs/scribble-lib/scriblib/figure.js b/pkgs/scribble-pkgs/scribble-lib/scriblib/figure.js new file mode 100644 index 00000000..b85af46c --- /dev/null +++ b/pkgs/scribble-pkgs/scribble-lib/scriblib/figure.js @@ -0,0 +1,27 @@ + +AddOnLoad(function () { + /* Lift figure targets to the start of the figure's blockquote, + so that clicking on a target reference shows the figure + content, instead of scrolling the figure caption to the + top of the page. */ + var targets = document.getElementsByTagName("a"); + for (var i = 0; i < targets.length; i++) { + var a = targets[i]; + var n = a.attributes["x-target-lift"]; + if (n) { + var s = n.value; + var p = a.parentNode; + while (p && (p.className != s)) { + p = p.parentNode; + } + if (p) { + var cs = p.children; + a.parentNode.removeChild(a); + if (cs.length > 0) + p.insertBefore(a, cs[0]); + else + p.appendChild(a); + } + } + } +}); diff --git a/pkgs/scribble-pkgs/scribble-lib/scriblib/figure.rkt b/pkgs/scribble-pkgs/scribble-lib/scriblib/figure.rkt index 5332df55..b965a184 100644 --- a/pkgs/scribble-pkgs/scribble-lib/scriblib/figure.rkt +++ b/pkgs/scribble-pkgs/scribble-lib/scriblib/figure.rkt @@ -47,6 +47,15 @@ (define centertext-style (make-style "Centertext" figure-style-extras)) +;; See "figure.js": +(define figure-target-style + (make-style #f + (list + (make-attributes '((x-target-lift . "Figure"))) + (make-js-addition + (path->main-collects-relative + (collection-file-path "figure.js" "scriblib")))))) + (define (make-figure-ref c s) (element (style "FigureRef" (list* (command-extras (list s)) figure-style-extras)) @@ -100,6 +109,7 @@ (counter-target figures tag "Figure" (if continue? " (continued): " ": ") + #:target-style figure-target-style #:continue? continue?)) (define (ref-proc initial) diff --git a/pkgs/scribble-pkgs/scribble-lib/scriblib/private/counter.rkt b/pkgs/scribble-pkgs/scribble-lib/scriblib/private/counter.rkt index e6482bed..ff85a685 100644 --- a/pkgs/scribble-pkgs/scribble-lib/scriblib/private/counter.rkt +++ b/pkgs/scribble-pkgs/scribble-lib/scriblib/private/counter.rkt @@ -19,13 +19,14 @@ `(,(string->symbol (format "counter-~a" kind)) ,tag) `(counter (,(counter-name counter) ,tag ,@kind)))) -(define (counter-target counter tag label +(define (counter-target counter tag label + #:target-style [target-style #f] #:continue? [continue? #f] . content) (let ([content (decode-content content)]) (define c (make-target-element - #f + target-style (list (make-collect-element #f