Skip to content

Commit a053f34

Browse files
committed
add 'show-language-family style property
1 parent 1752a4e commit a053f34

File tree

5 files changed

+104
-9
lines changed

5 files changed

+104
-9
lines changed

scribble-doc/scribblings/scribble/core.scrbl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,12 @@ The recognized @tech{style properties} are as follows:
497497
controls only when the viewing context indicates a language
498498
family not in the page's language families.}
499499

500+
@item{@indexed-racket['show-language-family] --- As a @tech{style
501+
property} for the main part of a rendered page or any enclosing
502+
part, causes the HTML output to include an indication of the
503+
document's primary language family, as well as the language
504+
family being used to navigate documentation.}
505+
500506
@item{@indexed-racket['no-header-controls] --- Suppresses link and
501507
link-information icons (if any) as part of a section header in
502508
HTML output.}
@@ -608,8 +614,9 @@ The @racket[parts] field contains sub-parts.
608614
#:changed "1.54" @elem{Changed @racket[tag-prefix] field to allow a
609615
@tech{part context} hash table.}
610616
#:changed "1.57" @elem{Added @racket['no-header-controls] support.}
611-
#:changed "1.59" @elem{Added @racket['no-navigation] and
612-
@racket['family-navigation] support.}]}
617+
#:changed "1.59" @elem{Added @racket['no-navigation],
618+
@racket['family-navigation], and
619+
@racket['show-language-family] support.}]}
613620

614621

615622
@defstruct[paragraph ([style style?] [content content?])]{

scribble-lib/scribble/html-render.rkt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,9 @@
825825
(define/public (extract-part-source d ri)
826826
(extract-inherited d ri document-source? document-source-module-path))
827827

828+
(define/public (extract-show-language-family d ri)
829+
(extract-inherited d ri (lambda (v) (eq? v 'show-language-family)) values))
830+
828831
(define/public (part-nesting-depth d ri)
829832
0)
830833

@@ -1028,7 +1031,8 @@
10281031
,@more)))))
10291032
(define no-nav? (and (memq 'no-navigation (style-properties (part-style d))) #t))
10301033
(define family-nav? (and (memq 'family-navigation (style-properties (part-style d))) #t))
1031-
(define fam (and family-nav?
1034+
(define show-fam? (extract-show-language-family d ri))
1035+
(define fam (and (or family-nav? show-fam?)
10321036
(or (search-extras (hash-ref (extend-part-context d) 'index-extras #hasheq()) 'language-family)
10331037
'("Racket"))))
10341038
(define (wrap-family c)
@@ -1118,9 +1122,21 @@
11181122
(define navbar
11191123
`(div ([class ,(if top? "navsettop" "navsetbottom")])
11201124
,navleft ,navright nbsp)) ; need nbsp to make the navset bg visible
1121-
(if (include-navigation?)
1122-
(list navbar)
1123-
null))
1125+
(append
1126+
(if (include-navigation?)
1127+
(list navbar)
1128+
null)
1129+
(if (and top? show-fam?)
1130+
(let ([fam (or fam '("Racket"))])
1131+
(list `(div ([class "navfamily"]
1132+
[data-fam ,(string-join fam ",")]
1133+
[data-fam-path ,(if search-up-path "../" "")]
1134+
[data-version ,(get-installation-name)])
1135+
,@(if (null? fam)
1136+
null
1137+
`((span ([class "docfamily"])
1138+
,(car fam)))))))
1139+
null)))
11241140

11251141
(define/override (render-one d ri fn)
11261142
(render-one-part d ri fn null))

scribble-lib/scribble/manual-style.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ it fouls up loading for reasons mysterious */
8686

8787

8888
/* Sans-serif: */
89-
.version, .versionNoNav, .ssansserif {
89+
.version, .versionNoNav, .ssansserif, .navfamily, .famlink {
9090
font-family: 'Fira', sans-serif;
9191
}
9292

@@ -311,6 +311,22 @@ a:hover {
311311
content: "v";
312312
}
313313

314+
/* ---------------------------------------- */
315+
/* Language Family */
316+
317+
.navfamily {
318+
position: absolute;
319+
float: none;
320+
top: 0.25rem;
321+
left: auto;
322+
right: 0rem;
323+
margin: 0em;
324+
margin-right: 1rem;
325+
height: auto;
326+
width: auto;
327+
font-size: 70%;
328+
font-weight: lighter;
329+
}
314330

315331
/* ---------------------------------------- */
316332
/* Margin notes */

scribble-lib/scribble/scribble-common.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ function GotoPLTRoot(ver, root_relative, here_to_root_relative) {
9797
var famroot = false;
9898
if (root_relative == "index.html") {
9999
famroot = (GetPageArg("fam", false) ? GetPageArg("famroot", false) : false)
100-
root_relative = famroot + "/index.html";
100+
if (famroot) {
101+
root_relative = famroot + "/index.html";
102+
}
101103
}
102104

103105
var u = GetRootPath(ver);
@@ -217,3 +219,40 @@ AddOnLoad(function(){
217219
}
218220
}
219221
});
222+
223+
AddOnLoad(function(){
224+
var es = document.getElementsByClassName("navfamily");
225+
for (var i=0; i < es.length; i++) {
226+
var e = es[i];
227+
if (e.dataset.fam != undefined) {
228+
var fams = e.dataset.fam.split(/,/);
229+
var fam = GetPageArg("fam", false);
230+
if (!fam) fam = "Racket";
231+
var link = document.createElement('a');
232+
var root = GetRootPath(e.dataset.version)
233+
var family_url;
234+
if (root == null) {
235+
family_url = new URL(e.dataset.famPath + "family/index.html", window.location.href);
236+
} else {
237+
family_url = new URL(root + "family/index.html", window.location.href);
238+
}
239+
family_url.searchParams.append("qfrom", window.location.href)
240+
if (fams.indexOf(fam) == -1) {
241+
var nav_as = document.createElement('div');
242+
link.textContent = "navigating as " + fam;
243+
link.href = family_url
244+
nav_as.appendChild(link)
245+
e.appendChild(nav_as)
246+
} else {
247+
var link = document.createElement('a');
248+
var span = e.children[0]
249+
link.textContent = span.textContent;
250+
link.href = family_url
251+
span.textContent = ''; // Clear span
252+
e.removeChild(span);
253+
link.appendChild(span);
254+
e.appendChild(link);
255+
}
256+
}
257+
}
258+
});

scribble-lib/scribble/scribble.css

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323

2424
/* Sans-serif: */
25-
.version, .versionNoNav, .ssansserif {
25+
.version, .versionNoNav, .ssansserif, .navfamily {
2626
font-family: sans-serif;
2727
}
2828
.ssansserif {
@@ -210,6 +210,23 @@ table td {
210210
content: "Version ";
211211
}
212212

213+
/* ---------------------------------------- */
214+
/* Language Family */
215+
216+
.navfamily {
217+
float: right;
218+
white-space: nowrap;
219+
left: 2em;
220+
height: 0em;
221+
width: 13em;
222+
margin: 0em -13em 0em 0em;
223+
font-size: small;
224+
}
225+
226+
.docfamily:after {
227+
content: " language family";
228+
}
229+
213230
/* ---------------------------------------- */
214231
/* Margin notes */
215232

0 commit comments

Comments
 (0)