Skip to content

Commit 2f1b30f

Browse files
committed
extension
1 parent ad8ad18 commit 2f1b30f

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
title: rev-history
2+
author: Lino Galiana
3+
version: 0.1.0
4+
quarto-required: ">=1.3.0"
5+
contributes:
6+
shortcodes:
7+
- callout-notebook.lua
8+
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
-- Liste des types de callouts et leur classe associée
2+
local callouts_all = {
3+
caution = "callout-caution",
4+
important = "callout-important",
5+
tip = "callout-tip",
6+
note = "callout-note",
7+
warning = "callout-warning",
8+
exercise = "callout-exercise"
9+
}
10+
11+
-- Fonction pour déterminer le type d’un callout à partir de ses classes
12+
function get_callout_type(div)
13+
for key, class in pairs(callouts_all) do
14+
if div.classes:includes(class) then
15+
return key
16+
end
17+
end
18+
return nil
19+
end
20+
21+
-- Applique le collapse si défini dans les métadonnées
22+
function applyCollapse(div, type, collapse_meta)
23+
if collapse_meta == nil then return div end
24+
25+
local collapse_val = nil
26+
if collapse_meta.all ~= nil then
27+
collapse_val = collapse_meta.all
28+
elseif collapse_meta[type] ~= nil then
29+
collapse_val = collapse_meta[type]
30+
end
31+
32+
if collapse_val ~= nil then
33+
div.attributes["collapse"] = tostring(collapse_val)
34+
end
35+
36+
return div
37+
end
38+
39+
-- Création du callout stylisé
40+
function createCallout(div, type, collapse_meta)
41+
local title = type:gsub("^%l", string.upper)
42+
43+
if div.content[1] and div.content[1].t == "Header" then
44+
title = pandoc.utils.stringify(div.content[1])
45+
div.content:remove(1)
46+
end
47+
48+
-- Appliquer collapse si spécifié
49+
div = applyCollapse(div, type, collapse_meta)
50+
51+
if quarto.doc.is_format("ipynb") then
52+
if type == "exercise" then
53+
type = "tip"
54+
end
55+
56+
local html_start = "<div class=\"callout callout-style-default callout-" .. type .. " callout-titled\">\n" ..
57+
"<div class=\"callout-header d-flex align-content-center\">\n" ..
58+
"<div class=\"callout-icon-container\">\n<i class=\"callout-icon\"></i>\n</div>\n" ..
59+
"<div class=\"callout-title-container flex-fill\">\n" .. title .. "\n</div>\n</div>\n" ..
60+
"<div class=\"callout-body-container callout-body\">\n"
61+
62+
local html_end = "</div>\n</div>"
63+
64+
div.content:insert(1, pandoc.RawBlock("html", html_start))
65+
div.content:insert(pandoc.RawBlock("html", html_end))
66+
67+
return div
68+
else
69+
return quarto.Callout({
70+
type = type,
71+
title = title,
72+
content = div.content,
73+
icon = div.attributes["icon"],
74+
collapse = div.attributes["collapse"] == "true"
75+
})
76+
end
77+
end
78+
79+
-- Hook principal
80+
function Div(div)
81+
local callout_type = get_callout_type(div)
82+
if callout_type ~= nil then
83+
local collapse_meta = quarto.doc and quarto.doc.metadata and quarto.doc.metadata["collapse-callout"]
84+
return createCallout(div, callout_type, collapse_meta)
85+
end
86+
end

0 commit comments

Comments
 (0)