Skip to content

Commit

Permalink
Add a color box to show which color it is as hexcode is not really th…
Browse files Browse the repository at this point in the history
…at readable in documentation
  • Loading branch information
cderv committed Nov 6, 2024
1 parent e58bb75 commit 1d39bd5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ format:

filters:
- filters/tools-tabset.lua
- filters/color-box.lua

freeze: true

Expand Down
15 changes: 8 additions & 7 deletions docs/presentations/revealjs/themes.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ Here's a list of all Sass variables (and their default values) used by Reveal th
+--------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| `$callout-color-<type>` | The colors for the various types of callouts. Defaults: |
| | |
| | | type | default | |
| | |-------------|-----------| |
| | | `note` | `#0d6efd` | |
| | | `tip` | `#198754` | |
| | | `caution` | `#dc3545` | |
| | | `warning` | `#fd7e14` | |
| | | `important` | `#ffc107` | |
| | | type | default | |
| | |-------------|-------------------------| |
| | | `note` | [`#0d6efd`]{.color-box} | |
| | | `tip` | [`#198754`]{.color-box} | |
| | | `caution` | [`#dc3545`]{.color-box} | |
| | | `warning` | [`#fd7e14`]{.color-box} | |
| | | `important` | [`#ffc107`]{.color-box} | |
| | |
| | Note that style for callout is to have left border using type color, and header background to use a variation of this color. |
+--------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Expand Down
18 changes: 18 additions & 0 deletions filters/color-box.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Span = function(s)
if not quarto.format.isHtmlOutput() then
return nil
end
if s.classes:includes('color-box') then
local color
if s.attributes['color'] then
quarto.log.output("HERE")
color = s.attributes['color']
s.attributes.color = nil
elseif #s.content == 1 and s.content[1] and s.content[1].t == "Code" and s.content[1].text and s.content[1].text:sub(1, 1) == '#' then
color = s.content[1].text
end
if color then
return pandoc.Span({ pandoc.Span('', pandoc.Attr('', { 'color-box' }, { style ="background-color:" .. color .. ";"})), s.content }, { "", { "color-box-container" } })
end
end
end
13 changes: 13 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,16 @@ iframe.reveal-demo {
.illustration {
border: 1px solid #dee2e6;
}

span.color-box-container {
display: inline-flex;
align-items: center; /* Align vertically */
}

span.color-box {
display: inline-block;
width: 1em; /* Width of the color box */
height: 1em; /* Height of the color box */
margin-right: 0.2em; /* Space between box and text */
border: 1px solid #000; /* Border color */
}

0 comments on commit 1d39bd5

Please sign in to comment.