Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/dev-docs/feature-format-matrix/_extensions/quarto-ext/fontawesome/fontawesome.lua
3589 views
1
local function ensureLatexDeps()
2
quarto.doc.use_latex_package("fontawesome5")
3
end
4
5
local function ensureHtmlDeps()
6
quarto.doc.add_html_dependency({
7
name = 'fontawesome6',
8
version = '0.1.0',
9
stylesheets = {'assets/css/all.css', 'assets/css/latex-fontsize.css'}
10
})
11
end
12
13
local function isEmpty(s)
14
return s == nil or s == ''
15
end
16
17
local function isValidSize(size)
18
local validSizes = {
19
"tiny",
20
"scriptsize",
21
"footnotesize",
22
"small",
23
"normalsize",
24
"large",
25
"Large",
26
"LARGE",
27
"huge",
28
"Huge"
29
}
30
for _, v in ipairs(validSizes) do
31
if v == size then
32
return size
33
end
34
end
35
return ""
36
end
37
38
return {
39
["fa"] = function(args, kwargs)
40
41
local group = "solid"
42
local icon = pandoc.utils.stringify(args[1])
43
if #args > 1 then
44
group = icon
45
icon = pandoc.utils.stringify(args[2])
46
end
47
48
local title = pandoc.utils.stringify(kwargs["title"])
49
if not isEmpty(title) then
50
title = " title=\"" .. title .. "\""
51
end
52
53
local label = pandoc.utils.stringify(kwargs["label"])
54
if isEmpty(label) then
55
label = " aria-label=\"" .. icon .. "\""
56
else
57
label = " aria-label=\"" .. label .. "\""
58
end
59
60
local size = pandoc.utils.stringify(kwargs["size"])
61
62
-- detect html (excluding epub which won't handle fa)
63
if quarto.doc.is_format("html:js") then
64
ensureHtmlDeps()
65
if not isEmpty(size) then
66
size = " fa-" .. size
67
end
68
return pandoc.RawInline(
69
'html',
70
"<i class=\"fa-" .. group .. " fa-" .. icon .. size .. "\"" .. title .. label .. "></i>"
71
)
72
-- detect pdf / beamer / latex / etc
73
elseif quarto.doc.is_format("pdf") then
74
ensureLatexDeps()
75
if isEmpty(isValidSize(size)) then
76
return pandoc.RawInline('tex', "\\faIcon{" .. icon .. "}")
77
else
78
return pandoc.RawInline('tex', "{\\" .. size .. "\\faIcon{" .. icon .. "}}")
79
end
80
else
81
return pandoc.Null()
82
end
83
end
84
}
85
86