Skip to content

Commit 140a355

Browse files
committed
feat: add explicit buttons to heading titles
This commit adds two buttons to each heading title. These buttons are by default hidden, but they will appear on hovering on the heading titles. The first button is a "link here" button, which adjusts the URL of the current page to include an anchor to link to that heading title, similar to how GitHub makes each heading title in README documents a link to add an anchor. The second button is to view Scribble source and internal link. Previously, clicking heading titles serves this functionality, but without an indicator that heading titles can be clicked, the feature is not discoverable. So this commit makes a transition toward an explicit button.
1 parent 3e12c25 commit 140a355

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

scribble-lib/scribble/html-render.rkt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"html-properties.rkt"
55
"private/literal-anchor.rkt"
66
racket/class
7+
racket/match
78
racket/path
89
racket/file
910
racket/port
@@ -1154,6 +1155,7 @@
11541155
(append
11551156
(if (and src taglet)
11561157
`([x-source-module ,(format "~s" src)]
1158+
[class "heading"]
11571159
,@(let* ([path (resolved-module-path-name
11581160
(module-path-index-resolve
11591161
(module-path-index-join src #f)))]
@@ -1170,14 +1172,32 @@
11701172
'())
11711173
(style->attribs (part-style d))))
11721174
,@(format-number number '((tt nbsp)))
1173-
,@(map (lambda (t)
1174-
`(a ([name ,(format "~a" (anchor-name
1175-
(add-current-tag-prefix
1176-
(tag-key t ri))))])))
1177-
(part-tags d))
11781175
,@(if (part-title-content d)
11791176
(render-content (part-title-content d) d ri)
1180-
null)))])
1177+
null)
1178+
" "
1179+
(span ([class "button-group"])
1180+
,@(let ([make-anchor
1181+
(lambda (t #:content [content '()])
1182+
`(a ([name ,(format "~a" (anchor-name
1183+
(add-current-tag-prefix
1184+
(tag-key t ri))))]
1185+
[href ,(format "#~a" (anchor-name
1186+
(add-current-tag-prefix
1187+
(tag-key t ri))))])
1188+
,@content))])
1189+
(match (part-tags d)
1190+
['() '()]
1191+
[(cons t ts)
1192+
(cons (make-anchor t
1193+
#:content
1194+
(list `(span ([class "heading-anchor"]
1195+
[title "Link here"])
1196+
"🔗")))
1197+
(map make-anchor ts))]))
1198+
" "
1199+
(a ([class "heading-source"]
1200+
[title "Internal Scribble link and Scribble source"]) ""))))])
11811201
,@(let ([auths (extract-authors d)])
11821202
(if (null? auths)
11831203
null

scribble-lib/scribble/manual-racket.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,15 @@ function AddPartTitleOnClick(elem) {
236236
else
237237
elem.parentNode.appendChild(info);
238238

239-
/* Clicking the header shows the explanation element: */
240-
elem.onclick = function () {
241-
if (info.style.display == "none")
239+
/* Clicking the information button shows the explanation element: */
240+
const heading = elem.querySelector('.heading-source');
241+
if (heading) {
242+
heading.onclick = function () {
243+
if (info.style.display === "none")
242244
info.style.display = "block";
243245
else
244246
info.style.display = "none";
247+
}
245248
}
246249
}
247250
}

scribble-lib/scribble/manual-style.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@
3131
font-size: 1rem;
3232
}
3333

34+
/** Begin headings */
35+
36+
/* Hide the button group by default, but show them on hovering the heading title */
37+
.heading:hover > .button-group {
38+
visibility: visible;
39+
}
40+
.button-group {
41+
visibility: hidden;
42+
}
43+
44+
.heading-anchor {
45+
font-size: 60%;
46+
/* A trick to color an emoji from https://stackoverflow.com/questions/32413731/color-for-unicode-emoji */
47+
color: transparent;
48+
text-shadow: 0 0 0 gray;
49+
vertical-align: 5%;
50+
}
51+
.heading-source {
52+
cursor: pointer;
53+
user-select: none;
54+
color: gray;
55+
}
56+
/** End headings */
57+
3458
/* embolden the "Racket Guide" and "Racket Reference" links on the TOC */
3559
/* there isn't an obvious tag in the markup that designates the top TOC page, which is called "start.scrbl" */
3660
/* nor a tag that designates these two links as special */

0 commit comments

Comments
 (0)