Night-mode styling, French cross-references, and the log through Part VI
- theme.scss and figures draw with the extension's --calc-… tokens; light/dark pair plus the high-contrast button; a11y highlight style for html - figure labels split so none leaves its viewBox in any language - _quarto-fr.yml: French cross-reference prefixes - notes extension synced to 2.8.18 - conv/: Parts IV, V and VI logged, pasted terminal output redacted Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
afb816f459
commit
f7fa60ba81
62 files changed
+3552
-852
No files matched your search
@@ -0,0 +1,134 @@
|
||||
-- further.lua — "to go further" notes, for material beside the lecture's own
|
||||
--
|
||||
-- ::: {.further}
|
||||
-- Everything in here is optional reading.
|
||||
-- :::
|
||||
--
|
||||
-- ::: {.further title="Cantor pairing"}
|
||||
-- ...
|
||||
-- :::
|
||||
--
|
||||
-- The box is purple, so it reads as an aside and never as the course's own
|
||||
-- statement. HTML: a box with a heading. PDF: a tcolorbox in the same colour.
|
||||
--
|
||||
-- Metadata:
|
||||
-- furthercolor: "#6B3FA0" # the accent of these notes
|
||||
-- further:
|
||||
-- label: "Pour aller plus loin" # defaults to the document `lang`
|
||||
|
||||
local LABELS = {
|
||||
en = "To go further",
|
||||
fr = "Pour aller plus loin",
|
||||
de = "Vertiefung",
|
||||
}
|
||||
|
||||
local DEFAULT_COLOR = "#6B3FA0"
|
||||
|
||||
local label = LABELS.en
|
||||
local color = DEFAULT_COLOR
|
||||
|
||||
local function fmt_is(name)
|
||||
if quarto and quarto.doc and quarto.doc.is_format then
|
||||
return quarto.doc.is_format(name)
|
||||
end
|
||||
return FORMAT ~= nil and FORMAT:match(name) ~= nil
|
||||
end
|
||||
|
||||
local function str(v)
|
||||
if v == nil then return nil end
|
||||
if type(v) == "boolean" then return tostring(v) end
|
||||
return pandoc.utils.stringify(v)
|
||||
end
|
||||
|
||||
local function esc_html(s)
|
||||
return (s:gsub("&", "&"):gsub("<", "<"):gsub(">", ">"):gsub('"', """))
|
||||
end
|
||||
|
||||
local function read_meta(meta)
|
||||
local lang = (str(meta.lang) or "en"):lower():gsub("[_-].*$", "")
|
||||
label = LABELS[lang] or LABELS.en
|
||||
if type(meta.further) == "table" and meta.further.label ~= nil then
|
||||
label = str(meta.further.label)
|
||||
end
|
||||
if meta.furthercolor ~= nil then
|
||||
color = str(meta.furthercolor)
|
||||
end
|
||||
local color_dark = meta["furthercolor-dark"] ~= nil
|
||||
and str(meta["furthercolor-dark"]) or nil
|
||||
|
||||
if quarto ~= nil and quarto.doc ~= nil then
|
||||
if fmt_is("html") then
|
||||
quarto.doc.add_html_dependency({
|
||||
name = "calc-further",
|
||||
version = "1.0.0",
|
||||
stylesheets = { "further.css" },
|
||||
})
|
||||
-- as for notecolor: the book's own colour is kept, and theme.css
|
||||
-- lifts it for a dark page instead of replacing it
|
||||
quarto.doc.include_text("in-header", table.concat({
|
||||
"<style>:root {",
|
||||
" --calc-furthercolor-src: " .. color .. ";",
|
||||
" --calc-furthercolor: var(--calc-furthercolor-src);",
|
||||
color_dark and (" --calc-furthercolor-dark: " .. color_dark .. ";") or "",
|
||||
"}</style>",
|
||||
}, "\n"))
|
||||
elseif fmt_is("latex") then
|
||||
-- same options as Quarto's callouts, so the two never clash
|
||||
quarto.doc.use_latex_package("tcolorbox", "skins,breakable")
|
||||
quarto.doc.use_latex_package("xcolor")
|
||||
quarto.doc.include_text("in-header",
|
||||
"\\definecolor{furthercolor}{HTML}{" .. color:gsub("^#", "") .. "}")
|
||||
end
|
||||
end
|
||||
return meta
|
||||
end
|
||||
|
||||
------------------------------------------------------------------ render
|
||||
|
||||
-- `sep`: what goes between the label and a title= of its own. LaTeX fonts
|
||||
-- often lack the U+2002 glyph, so the pdf gets \enspace instead.
|
||||
local function head_text(el, sep)
|
||||
local title = el.attributes.title
|
||||
if title ~= nil and title ~= "" then
|
||||
return label .. (sep or "\u{2002}—\u{2002}") .. title
|
||||
end
|
||||
return label
|
||||
end
|
||||
|
||||
local function html_box(el)
|
||||
local blocks = pandoc.Blocks({ pandoc.RawBlock("html",
|
||||
'<div class="further"><div class="further-head">'
|
||||
.. esc_html(head_text(el)) .. '</div><div class="further-body">') })
|
||||
blocks:extend(el.content)
|
||||
blocks:insert(pandoc.RawBlock("html", "</div></div>"))
|
||||
return blocks
|
||||
end
|
||||
|
||||
local function latex_box(el)
|
||||
local blocks = pandoc.Blocks({ pandoc.RawBlock("latex",
|
||||
"\\begin{tcolorbox}[enhanced jigsaw,breakable,"
|
||||
.. "colback=furthercolor!4!white,colframe=furthercolor!55!white,"
|
||||
.. "boxrule=0.4pt,arc=1pt,colbacktitle=furthercolor!12!white,"
|
||||
.. "coltitle=furthercolor!80!black,fonttitle=\\small\\bfseries,"
|
||||
.. "title={" .. head_text(el, "\\enspace---\\enspace{}") .. "},"
|
||||
.. "left=2mm,right=1.5mm,top=1mm,bottom=1mm]") })
|
||||
blocks:extend(el.content)
|
||||
blocks:insert(pandoc.RawBlock("latex", "\\end{tcolorbox}"))
|
||||
return blocks
|
||||
end
|
||||
|
||||
local function Div(el)
|
||||
if not el.classes:includes("further") then return nil end
|
||||
if fmt_is("html") then return html_box(el) end
|
||||
if fmt_is("latex") then return latex_box(el) end
|
||||
-- any other format: a plain titled block
|
||||
local blocks = pandoc.Blocks({
|
||||
pandoc.Para({ pandoc.Strong({ pandoc.Str(head_text(el) .. ".") }) }) })
|
||||
blocks:extend(el.content)
|
||||
return pandoc.Div(blocks, pandoc.Attr("", { "further" }))
|
||||
end
|
||||
|
||||
return {
|
||||
{ Meta = read_meta },
|
||||
{ Div = Div },
|
||||
}
|
||||
Reference in new issue
Block a user