-
Notifications
You must be signed in to change notification settings - Fork 162
/
custom_callout.lua
61 lines (54 loc) · 2.11 KB
/
custom_callout.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
local callouts = {}
-- Helper function to extract options from div attributes or content
local function extractOptions(div, defaultType)
local options = {
type = defaultType,
collapse = div.attributes["collapse"] == "true",
appearance = "minimal",
icon = defaultType == "colab" and "👩💻" or
defaultType == "question" and "❓" or
defaultType == "hint" and "🤔" or
defaultType == "answer" and "✅" or
defaultType == "slide" and "🎫" or
defaultType == "video" and "📺" or
defaultType == "lab" and "🧪"
}
if div.attr and div.attr.identifier ~= "" then
options.id = div.attr.identifier
end
if div.content[1] ~= nil and div.content[1].t == "Header" then
options.title = pandoc.utils.stringify(div.content[1])
table.remove(div.content, 1)
end
options.content = pandoc.Blocks(div.content)
return options
end
-- Function to create a callout with specified options
local function createCallout(div, calloutType)
local options = extractOptions(div, calloutType)
if options.id then
callouts[options.id] = options
print("Collected callout with ID:", options.id)
end
return quarto.Callout(options)
end
-- Main Div function
function Div(div)
if quarto.doc.isFormat("html") then
if div.classes:includes("callout-warning") then
return createCallout(div, "colab")
elseif div.classes:includes("callout-answer") then
return createCallout(div, "answer")
elseif div.classes:includes("callout-hint") then
return createCallout(div, "hint")
elseif div.classes:includes("callout-lab") then
return createCallout(div, "lab")
elseif div.classes:includes("callout-slide") then
return createCallout(div, "slide")
elseif div.classes:includes("callout-question") then
return createCallout(div, "question")
elseif div.classes:includes("callout-video") then
return createCallout(div, "video")
end
end
end