Skip to content

Commit c392cbb

Browse files
committed
Use iconify instead
1 parent 80b1f63 commit c392cbb

18 files changed

+198
-8161
lines changed
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) 2024 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 support
2+
author: Mickaël Canouil
3+
version: 2.1.2
4+
quarto-required: ">=1.2.280"
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: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
--[[
2+
# MIT License
3+
#
4+
# Copyright (c) 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 function ensure_html_deps()
26+
quarto.doc.add_html_dependency({
27+
name = 'iconify',
28+
version = '2.1.0',
29+
scripts = {"iconify-icon.min.js"}
30+
})
31+
end
32+
33+
local function is_empty(s)
34+
return s == nil or s == ''
35+
end
36+
37+
local function is_valid_size(size)
38+
if is_empty(size) then
39+
return ''
40+
end
41+
local size_table = {
42+
["tiny"] = "0.5em",
43+
["scriptsize"] = "0.7em",
44+
["footnotesize"] = "0.8em",
45+
["small"] = "0.9em",
46+
["normalsize"] = "1em",
47+
["large"] = "1.2em",
48+
["Large"] = "1.5em",
49+
["LARGE"] = "1.75em",
50+
["huge"] = "2em",
51+
["Huge"] = "2.5em",
52+
["1x"] = "1em",
53+
["2x"] = "2em",
54+
["3x"] = "3em",
55+
["4x"] = "4em",
56+
["5x"] = "5em",
57+
["6x"] = "6em",
58+
["7x"] = "7em",
59+
["8x"] = "8em",
60+
["9x"] = "9em",
61+
["10x"] = "10em",
62+
["2xs"] = "0.625em",
63+
["xs"] = "0.75em",
64+
["sm"] = "0.875em",
65+
["lg"] = "1.25em",
66+
["xl"] = "1.5em",
67+
["2xl"] = "2em"
68+
}
69+
for key, value in pairs(size_table) do
70+
if key == size then
71+
return 'font-size: ' .. value .. ';'
72+
end
73+
end
74+
return 'font-size: ' .. size .. ';'
75+
end
76+
77+
return {
78+
["iconify"] = function(args, kwargs)
79+
-- detect html (excluding epub which won't handle fa)
80+
if quarto.doc.is_format("html:js") then
81+
ensure_html_deps()
82+
local icon = pandoc.utils.stringify(args[1])
83+
local set = "fluent-emoji"
84+
85+
if #args > 1 and string.find(pandoc.utils.stringify(args[2]), ":") then
86+
quarto.log.warning(
87+
'Use "set:icon" or "set icon" syntax, not both! ' ..
88+
'Using "set:icon" syntax and discarding first argument!'
89+
)
90+
icon = pandoc.utils.stringify(args[2])
91+
end
92+
93+
if string.find(icon, ":") then
94+
set = string.sub(icon, 1, string.find(icon, ":") - 1)
95+
icon = string.sub(icon, string.find(icon, ":") + 1)
96+
elseif #args > 1 then
97+
set = icon
98+
icon = pandoc.utils.stringify(args[2])
99+
end
100+
101+
local attributes = ' icon="' .. set .. ':' .. icon .. '"'
102+
local default_label = 'Icon ' .. icon .. ' from ' .. set .. ' Iconify.design set.'
103+
104+
local size = is_valid_size(pandoc.utils.stringify(kwargs["size"]))
105+
if not is_empty(size) then
106+
attributes = attributes .. ' style="' .. size .. '"'
107+
end
108+
109+
local aria_label = pandoc.utils.stringify(kwargs["label"])
110+
if is_empty(aria_label) then
111+
aria_label = ' aria-label="' .. default_label .. '"'
112+
else
113+
aria_label = ' aria-label="' .. aria_label .. '"'
114+
end
115+
116+
local title = pandoc.utils.stringify(kwargs["title"])
117+
if is_empty(title) then
118+
title = ' title="' .. default_label .. '"'
119+
else
120+
title = ' title="' .. title .. '"'
121+
end
122+
123+
attributes = attributes .. aria_label .. title
124+
125+
local width = pandoc.utils.stringify(kwargs["width"])
126+
if not is_empty(width) and is_empty(size) then
127+
attributes = attributes .. ' width="' .. width .. '"'
128+
end
129+
local height = pandoc.utils.stringify(kwargs["height"])
130+
if not is_empty(height) and is_empty(size) then
131+
attributes = attributes .. ' height="' .. height .. '"'
132+
end
133+
local flip = pandoc.utils.stringify(kwargs["flip"])
134+
if not is_empty(flip) then
135+
attributes = attributes .. ' flip="' .. flip.. '"'
136+
end
137+
local rotate = pandoc.utils.stringify(kwargs["rotate"])
138+
if not is_empty(rotate) then
139+
attributes = attributes .. ' rotate="' .. rotate .. '"'
140+
end
141+
142+
local inline = pandoc.utils.stringify(kwargs["inline"])
143+
if is_empty(inline) or inline ~= "false" then
144+
attributes = ' inline ' .. attributes
145+
end
146+
147+
148+
return pandoc.RawInline(
149+
'html',
150+
'<iconify-icon role="img"' .. attributes .. '></iconify-icon>'
151+
)
152+
else
153+
return pandoc.Null()
154+
end
155+
end
156+
}

_extensions/quarto-ext/fontawesome/_extension.yml

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

0 commit comments

Comments
 (0)