Skip to content

Commit 59f1768

Browse files
authored
New function: section_outline (#67)
1 parent 022ecda commit 59f1768

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PlutoTeachingTools"
22
uuid = "661c6b06-c737-4d37-b85c-46df65de6f69"
33
authors = ["Eric Ford <[email protected]> and contributors"]
4-
version = "0.4.1"
4+
version = "0.4.2"
55

66
[deps]
77
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

src/PlutoTeachingTools.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export code_for_check_type_funcs
2525
export TODO, nbsp
2626
export blockquote
2727
export display_msg_if_fail
28+
export section_outline
2829

2930
include("present.jl")
3031
export present_button

src/computational_thinking.jl

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,89 @@ function blockquote(text, author="")
346346
</style>
347347
""")
348348
end
349+
350+
351+
"""
352+
A clear visual indicator of a section, with a colored outline. You use this function at the start of a section.
353+
354+
The outline extends below the cell, which makes it useful to visually group multiple cells together.
355+
356+
```julia
357+
section_outline(
358+
section_type::String,
359+
section_title::String;
360+
color::String="green", # this can be any valid CSS color
361+
big::Bool=false, # if true, the outline will be larger
362+
header_level::Int=2, # the level of the header to use. 2 means a ## header, 3 means a ### header, etc.
363+
)
364+
```
365+
366+
367+
# Example
368+
369+
```julia
370+
section_outline("Example:", "Finding the roots of a polynomial"; color="red")
371+
```
372+
373+
```julia
374+
md"\""
375+
Let's find the roots of the polynomial ``x^2 - 4x + 4 = 0``.
376+
""\"
377+
```
378+
379+
```julia
380+
f(x) = x^2 - 4x + 4
381+
```
382+
383+
```julia
384+
f(2.0)
385+
```
386+
387+
> This looks like:
388+
>
389+
> ![Screenshot of the section outline from the code above](https://i.imgur.com/2cYDNiv.png)
390+
391+
"""
392+
section_outline(
393+
section_text,
394+
title;
395+
color="green",
396+
big::Bool=false,
397+
header_level::Int=2,
398+
) = @htl """
399+
<$("h$header_level") class="ptt-section $(big ? "big" : "")" style="--ptt-accent: $(color);"><span>$(section_text)</span> $(title)</$("h$header_level")>
400+
401+
<style>
402+
.ptt-section::before {
403+
content: "";
404+
display: block;
405+
position: absolute;
406+
left: -25px;
407+
right: -6px;
408+
top: -4px;
409+
height: 200px;
410+
border: 4px solid salmon;
411+
border-bottom: none;
412+
border-image-source: linear-gradient(to bottom, var(--ptt-accent), transparent);
413+
border-image-slice: 1;
414+
opacity: .7;
415+
pointer-events: none;
416+
}
417+
418+
.big.ptt-section::before {
419+
height: 500px;
420+
}
421+
422+
423+
.ptt-section > span {
424+
color: color-mix(in hwb, var(--ptt-accent) 60%, black);
425+
@media (prefers-color-scheme: dark) {
426+
color: color-mix(in hwb, var(--ptt-accent) 30%, white);
427+
}
428+
font-style: italic;
429+
}
430+
431+
432+
</style>
433+
"""
434+

0 commit comments

Comments
 (0)