Skip to content

Commit f633613

Browse files
authored
Merge pull request #939 from DirectXMan12/docs/fancy-details-styles
📖 Make the code expandos a bit more pretty
2 parents 97d6111 + 1d2b7fa commit f633613

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

docs/book/theme/css/general.css

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,69 @@ input.markers-summarize:checked ~ label.markers-summarize::before {
352352
}
353353

354354
/* details elements (not markers) */
355-
main > details.collapse-code > summary {
356-
font-size: 80%;
357-
opacity: 0.7;
355+
details.collapse-code {
356+
margin-top: 0.125em;
357+
margin-bottom: 0.125em;
358+
}
359+
360+
details.collapse-code > summary {
361+
width: 100%;
362+
cursor: pointer;
363+
display: flex;
364+
box-sizing: border-box; /* why isn't this the default? :-/ */
365+
}
366+
367+
details.collapse-code > summary::after {
368+
content: "\25c0";
369+
float: right;
370+
font-size: 0.875em;
371+
color: var(--inline-code-color);
372+
opacity: 0.8;
373+
}
374+
375+
details.collapse-code[open] > summary::after {
376+
content: "\25bc";
358377
}
359378

360-
main > details.collapse-code > summary::after {
379+
details.collapse-code > summary pre {
380+
flex: 1;
381+
box-sizing: border-box; /* why isn't this the default? :-/ */
382+
margin: inherit;
383+
padding: 0.25em 0.5em;
384+
}
385+
386+
details.collapse-code > summary pre span::after {
361387
content: " (hidden)";
388+
font-size: 80%;
389+
}
390+
391+
details.collapse-code[open] > summary pre span::after {
392+
content: "";
393+
}
394+
395+
details.collapse-code > summary pre span::before {
396+
content: "// ";
397+
}
398+
399+
/* make summary into code a bit nicer looking */
400+
details.collapse-code[open] > summary + pre {
401+
margin-top: 0;
402+
}
403+
404+
/* get rid of the ugly blue box that makes the summary->code look bad */
405+
details.collapse-code summary:focus {
406+
outline: none;
407+
font-weight: bold; /* keep something around for tab users */
408+
}
409+
410+
/* don't show the default expando */
411+
details.collapse-code > summary {
412+
list-style: none;
362413
}
414+
details.collapse-code > summary::-webkit-details-marker {
415+
display: none;
416+
}
417+
363418

364419
/* diagrams */
365420

docs/book/utils/litgo/literate.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,12 @@ func (l Literate) extractContents(contents []byte, pathInfo filePathInfo) (strin
239239

240240
for _, pair := range pairs {
241241
if pair.collapse != "" {
242-
out.WriteString("<details class=\"collapse-code\"><summary>")
242+
// NB(directxman12): we add the hljs class to "cheat" and get the
243+
// right background with theming, since hljs doesn't use CSS
244+
// variables.
245+
out.WriteString("<details class=\"collapse-code\"><summary class=\"hljs\"><pre class=\"hljs\"><span class=\"hljs-comment\">")
243246
out.WriteString(pair.collapse)
244-
out.WriteString("</summary>")
247+
out.WriteString("</span></pre></summary>")
245248
}
246249
if strings.TrimSpace(pair.comment) != "" {
247250
out.WriteString("\n")

0 commit comments

Comments
 (0)