Skip to content

Commit d003909

Browse files
authored
Improve dark mode and page lisibility (#611)
* typo1 * titre * better dark mode handling * homagepage
1 parent 9c1fd72 commit d003909

13 files changed

Lines changed: 516 additions & 438 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Mickaël Canouil
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: Iconify
2+
author: Mickaël Canouil
3+
version: 3.0.0
4+
quarto-required: ">=1.5.57"
5+
contributes:
6+
shortcodes:
7+
- iconify.lua

‎_extensions/mcanouil/iconify/iconify-icon.min.js‎

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
--[[
2+
# MIT License
3+
#
4+
# Copyright (c) 2025 Mickaël Canouil
5+
#
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
13+
# The above copyright notice and this permission notice shall be included in all
14+
# copies or substantial portions of the Software.
15+
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
# SOFTWARE.
23+
]]
24+
25+
local stringify = pandoc.utils.stringify
26+
27+
--- Ensure Iconify HTML dependencies are included.
28+
--- @return nil
29+
local function ensure_html_deps()
30+
quarto.doc.add_html_dependency({
31+
name = 'iconify',
32+
version = '3.0.0',
33+
scripts = { 'iconify-icon.min.js' }
34+
})
35+
end
36+
37+
--- Check if a string is empty or nil.
38+
--- @param s string|nil
39+
--- @return boolean
40+
local function is_empty(s)
41+
return s == nil or s == ''
42+
end
43+
44+
--- Validate and convert size keyword to CSS font-size.
45+
--- @param size string|nil
46+
--- @return string
47+
local function is_valid_size(size)
48+
if is_empty(size) then
49+
return ''
50+
end
51+
local size_table = {
52+
["tiny"] = "0.5em",
53+
["scriptsize"] = "0.7em",
54+
["footnotesize"] = "0.8em",
55+
["small"] = "0.9em",
56+
["normalsize"] = "1em",
57+
["large"] = "1.2em",
58+
["Large"] = "1.5em",
59+
["LARGE"] = "1.75em",
60+
["huge"] = "2em",
61+
["Huge"] = "2.5em",
62+
["1x"] = "1em",
63+
["2x"] = "2em",
64+
["3x"] = "3em",
65+
["4x"] = "4em",
66+
["5x"] = "5em",
67+
["6x"] = "6em",
68+
["7x"] = "7em",
69+
["8x"] = "8em",
70+
["9x"] = "9em",
71+
["10x"] = "10em",
72+
["2xs"] = "0.625em",
73+
["xs"] = "0.75em",
74+
["sm"] = "0.875em",
75+
["lg"] = "1.25em",
76+
["xl"] = "1.5em",
77+
["2xl"] = "2em"
78+
}
79+
for key, value in pairs(size_table) do
80+
if key == size then
81+
return 'font-size: ' .. value .. ';'
82+
end
83+
end
84+
return 'font-size: ' .. size .. ';'
85+
end
86+
87+
--- Get iconify option from arguments or metadata.
88+
--- @param x string
89+
--- @param arg table
90+
--- @param meta table
91+
--- @return string
92+
local function get_iconify_options(x, arg, meta)
93+
local arg_value = stringify(arg[x])
94+
if is_empty(meta['iconify']) or not is_empty(arg_value) then
95+
return arg_value
96+
end
97+
if not is_empty(meta['iconify'][x]) then
98+
return stringify(meta['iconify'][x])
99+
end
100+
return arg_value
101+
end
102+
103+
--- Render an Iconify icon as a Pandoc RawInline for HTML output.
104+
--- @param args table Icon arguments (icon set and name).
105+
--- @param kwargs table Key-value options for the icon.
106+
--- @param meta table Document metadata.
107+
--- @return pandoc.Inline|pandoc.Null
108+
function iconify(args, kwargs, meta)
109+
-- detect html (excluding epub which won't handle fa)
110+
if quarto.doc.is_format("html:js") then
111+
ensure_html_deps()
112+
local icon = stringify(args[1])
113+
local set = 'octicon'
114+
if not is_empty(meta['iconify']) and not is_empty(meta['iconify']['set']) then
115+
set = stringify(meta['iconify']['set'])
116+
end
117+
118+
if #args > 1 and string.find(stringify(args[2]), ':') then
119+
quarto.log.warning(
120+
'Use "set:icon" or "set icon" syntax, not both! ' ..
121+
'Using "set:icon" syntax and discarding first argument!'
122+
)
123+
icon = stringify(args[2])
124+
end
125+
126+
if string.find(icon, ":") then
127+
set = string.sub(icon, 1, string.find(icon, ":") - 1)
128+
icon = string.sub(icon, string.find(icon, ":") + 1)
129+
elseif #args > 1 then
130+
set = icon
131+
icon = stringify(args[2])
132+
end
133+
134+
local attributes = ' icon="' .. set .. ':' .. icon .. '"'
135+
local default_label = 'Icon ' .. icon .. ' from ' .. set .. ' Iconify.design set.'
136+
137+
local size = is_valid_size(get_iconify_options("size", kwargs, meta))
138+
local style = get_iconify_options("style", kwargs, meta)
139+
140+
if is_empty(style) and not is_empty(size) then
141+
attributes = attributes .. ' style="' .. size .. '"'
142+
elseif not is_empty(style) and not is_empty(size) then
143+
attributes = attributes .. ' style="' .. style .. ';' .. size .. '"'
144+
elseif not is_empty(style) then
145+
attributes = attributes .. ' style="' .. style .. '"'
146+
end
147+
148+
local aria_label = stringify(kwargs["label"])
149+
if is_empty(aria_label) then
150+
aria_label = ' aria-label="' .. default_label .. '"'
151+
else
152+
aria_label = ' aria-label="' .. aria_label .. '"'
153+
end
154+
155+
local title = stringify(kwargs["title"])
156+
if is_empty(title) then
157+
title = ' title="' .. default_label .. '"'
158+
else
159+
title = ' title="' .. title .. '"'
160+
end
161+
162+
attributes = attributes .. aria_label .. title
163+
164+
local width = get_iconify_options("width", kwargs, meta)
165+
if not is_empty(width) and is_empty(size) then
166+
attributes = attributes .. ' width="' .. width .. '"'
167+
end
168+
local height = get_iconify_options("height", kwargs, meta)
169+
if not is_empty(height) and is_empty(size) then
170+
attributes = attributes .. ' height="' .. height .. '"'
171+
end
172+
local flip = get_iconify_options("flip", kwargs, meta)
173+
if not is_empty(flip) then
174+
attributes = attributes .. ' flip="' .. flip.. '"'
175+
end
176+
local rotate = get_iconify_options("rotate", kwargs, meta)
177+
if not is_empty(rotate) then
178+
attributes = attributes .. ' rotate="' .. rotate .. '"'
179+
end
180+
181+
local inline = get_iconify_options("inline", kwargs, meta)
182+
if is_empty(inline) or inline ~= "false" then
183+
attributes = ' inline ' .. attributes
184+
end
185+
186+
local mode = get_iconify_options("mode", kwargs, meta)
187+
local valid_modes = { svg = true, style = true, bg = true, mask = true }
188+
if not is_empty(mode) and valid_modes[mode] then
189+
attributes = attributes .. ' mode="' .. mode .. '"'
190+
end
191+
192+
return pandoc.RawInline(
193+
'html',
194+
'<iconify-icon role="img"' .. attributes .. '></iconify-icon>'
195+
)
196+
else
197+
return pandoc.Null()
198+
end
199+
end
200+
201+
return {
202+
["iconify"] = iconify
203+
}

‎_quarto-prod.yml‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,18 @@ website:
9292

9393
format:
9494
html:
95+
include-after-body: build/js/mac.html
96+
respect-user-color-scheme: true
9597
theme:
96-
light: [lightly, styles/custom.scss, styles/custom-light.scss]
97-
dark: [darkly, styles/custom.scss, styles/custom-dark.scss]
98+
light: [cosmo, styles/custom.scss, styles/custom-light.scss]
99+
dark: [cosmo, styles/custom.scss, styles/custom-dark.scss]
98100
css: styles/styles.css
99101
toc: true
100102
code-overflow: wrap
101-
include-in-header:
102-
- build/toggle.js
103+
grid:
104+
sidebar-width: 250px
105+
body-width: 900px
106+
margin-width: 300px
103107
ipynb: default
104108

105109

@@ -127,4 +131,4 @@ keep-ipynb: true
127131
lightbox: auto
128132
google-scholar: true
129133
commentable: true
130-
134+
highlight-style: a11y

‎_quarto.yml‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,22 @@ website:
6262

6363
format:
6464
html:
65+
include-after-body: build/js/mac.html
66+
respect-user-color-scheme: true
6567
theme:
66-
light: [lightly, styles/custom.scss, styles/custom-light.scss]
67-
dark: [darkly, styles/custom.scss, styles/custom-dark.scss]
68+
light: [cosmo, styles/custom.scss, styles/custom-light.scss]
69+
dark: [cosmo, styles/custom.scss, styles/custom-dark.scss]
6870
css: styles/styles.css
6971
toc: true
7072
code-overflow: wrap
71-
include-in-header:
72-
- build/toggle.js
73+
grid:
74+
sidebar-width: 250px
75+
body-width: 900px
76+
margin-width: 300px
7377
ipynb: default
7478

7579

80+
7681
# PAGE OPTIONS ---------------------
7782

7883
filters:
@@ -99,4 +104,5 @@ keep-ipynb: true
99104
lightbox: auto
100105
google-scholar: true
101106
commentable: true
107+
highlight-style: a11y
102108

‎build/js/mac.html‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script type="text/javascript">
2+
3+
// replace cmd keyboard shortcut w/ control on non-Mac platforms
4+
const kPlatformMac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false;
5+
if (!kPlatformMac) {
6+
var kbds = document.querySelectorAll("kbd")
7+
kbds.forEach(function(kbd) {
8+
kbd.innerHTML = kbd.innerHTML.replace(/⌘/g, '⌃');
9+
});
10+
}
11+
12+
// tweak headings in pymd
13+
document.querySelectorAll(".pymd span.co").forEach(el => {
14+
if (!el.innerText.startsWith("#|")) {
15+
el.style.fontWeight = 1000;
16+
}
17+
});
18+
19+
</script>

‎build/toggle.js‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎content/getting-started/01_environment.qmd‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ description-en: |
99
---
1010

1111

12-
```{python}
13-
#| echo: true
14-
import pandas as pd
15-
x = [0]
16-
```
17-
18-
1912
::: {.content-visible when-profile="fr"}
2013
:::: {.tip}
2114
## Objet de ce chapitre
@@ -294,7 +287,7 @@ It is discouraged to use global imports like `from pkg import *`. For example, c
294287
::::
295288
:::
296289

297-
```python
290+
```{.python}
298291
# Don't do that please !
299292
from numpy import *
300293
from math import *

0 commit comments

Comments
 (0)