Skip to content

Commit 86bfd0c

Browse files
committed
Merge branch 'main' of github.com:quarto-dev/quarto-cli into main
2 parents 53e42d5 + 99622af commit 86bfd0c

File tree

3 files changed

+81
-24
lines changed

3 files changed

+81
-24
lines changed

design/TODO.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ JJ:
2626

2727

2828
CT:
29-
- redo callout latex to not use awesomebox so callouts look sweet
3029
- search highlighting like is done in mastering-shiny
3130
(https://mastering-shiny.org/performance.html?q=plot#caching-plots)
3231
jumping between highlighted terms (via keyboard or affordance at right or top)

src/resources/filters/quarto-pre/callout.lua

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function calloutDiv(div)
184184
return calloutDiv
185185
end
186186

187-
-- Latex awesomebox callout
187+
-- Latex callout
188188
function calloutLatex(div)
189189

190190
-- read and clear attributes
@@ -194,40 +194,95 @@ function calloutLatex(div)
194194
div.attr.attributes["icon"] = nil
195195
div.attr.attributes["caption"] = nil
196196
div.attr.attributes["collapse"] = nil
197-
198-
local calloutContents = pandoc.List:new({});
199-
197+
200198
-- Add the captions and contents
199+
local calloutContents = pandoc.List:new({});
201200
if caption ~= nil then
202201
calloutContents:insert(pandoc.Para(pandoc.Strong(caption)))
203202
end
204203
tappend(calloutContents, div.content)
205204

206-
-- Add the environment info, using inlines if possible
205+
-- generate the callout box
206+
local callout = latexCalloutBox(type)
207+
local beginEnvironment = callout.beginInlines;
208+
local endEnvironment = callout.endInlines;
209+
210+
if calloutContents[1].t == "Para" and calloutContents[#calloutContents].t == "Para" then
211+
tprepend(calloutContents[1].content, beginEnvironment)
212+
tappend(calloutContents[#calloutContents].content, endEnvironment)
213+
else
214+
tprepend(calloutContents, pandoc.Para(beginEnvironment))
215+
tappend(calloutContents, pandoc.Para(endEnvironment))
216+
end
217+
218+
219+
return pandoc.Div(calloutContents)
220+
end
221+
222+
-- create the tcolorBox
223+
function latexCalloutBox(type, icon)
224+
225+
-- calllout dimensions
226+
local leftBorderWidth = '1mm'
227+
local borderWidth = '.15mm'
228+
local borderRadius = '.15mm'
229+
local leftPad = '2mm'
207230
local color = latexColorForType(type)
208-
local leftMarginWidth = '0'
231+
232+
-- generate options
233+
local options = {
234+
colframe = color,
235+
colback = 'white',
236+
left = leftPad,
237+
leftrule = leftBorderWidth,
238+
toprule = borderWidth,
239+
bottomrule = borderWidth,
240+
rightrule = borderWidth,
241+
arc = borderRadius,
242+
}
243+
244+
-- the core latex for the box
245+
local beginInlines = { pandoc.RawInline('latex', '\\begin{tcolorbox}[' .. tColorOptions(options) .. ']\n') }
246+
local endInlines = { pandoc.RawInline('latex', '\n\\end{tcolorbox}') }
247+
248+
-- generate the icon and use a minipage to position it
209249
local iconForType = iconForType(type)
210-
local iconName = ''
211250
if icon ~= false and iconForType ~= nil then
212-
iconName = '\\' .. iconForType
213-
leftMarginWidth = '0.12'
251+
local iconName = '\\' .. iconForType
252+
local iconColSize = '5.5mm'
253+
254+
-- add an icon to the begin
255+
local iconTex = '\\begin{minipage}[t]{' .. iconColSize .. '}\n\\textcolor{' .. color .. '}{' .. iconName .. '}\n\\end{minipage}%\n\\begin{minipage}[t]{\\textwidth - ' .. iconColSize .. '}\n'
256+
tappend(beginInlines, {pandoc.RawInline('latex', iconTex)})
257+
258+
-- close the icon
259+
tprepend(endInlines, {pandoc.RawInline('latex', '\\end{minipage}%')});
214260
end
215-
local separatorWidth = '1pt'
216261

217-
local leftMargin = pandoc.RawInline('latex', '\\setlength{\\aweboxleftmargin}{' .. leftMarginWidth .. '\\linewidth}');
218-
local beginEnvironment = pandoc.RawInline('latex', '\\begin{awesomeblock}[' .. color .. ']{' .. separatorWidth .. '}{' .. iconName .. '}{' .. color ..'}\n')
219-
local endEnvironment = pandoc.RawInline('latex', '\n\\end{awesomeblock}')
220-
if calloutContents[1].t == "Para" and calloutContents[#calloutContents].t == "Para" then
221-
table.insert(calloutContents[1].content, 1, beginEnvironment)
222-
table.insert(calloutContents[1].content, 1, leftMargin)
223-
table.insert(calloutContents[#calloutContents].content, endEnvironment)
224-
else
225-
table.insert(calloutContents, 1, pandoc.Para({beginEnvironment}))
226-
table.insert(calloutContents, pandoc.Para({endEnvironment}))
262+
-- the inlines
263+
return {
264+
beginInlines = beginInlines,
265+
endInlines = endInlines
266+
}
267+
end
268+
269+
-- generates a set of options for a tColorBox
270+
function tColorOptions(options)
271+
272+
local optionStr = ""
273+
local prepend = false
274+
for k, v in pairs(options) do
275+
if (prepend) then
276+
optionStr = optionStr .. ', '
277+
end
278+
optionStr = optionStr .. k .. '=' .. v
279+
prepend = true
227280
end
228-
return pandoc.Div(calloutContents)
281+
return optionStr
282+
229283
end
230284

285+
231286
function calloutDocx(div)
232287

233288
local hasIcon, type, contents = resolveCalloutContents(div, false)
@@ -447,7 +502,7 @@ function iconForType(type)
447502
elseif type == "caution" then
448503
return "faBurn"
449504
elseif type == "tip" then
450-
return "faLightbulb"
505+
return "faLightbulbO"
451506
else
452507
return nil
453508
end

src/resources/filters/quarto-pre/meta.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ function quartoPreMetaInject()
1010
if preState.hasCallouts and isLatexOutput() then
1111
metaInjectLatex(meta, function(inject)
1212
inject(
13-
usePackage("awesomebox")
13+
usePackage("tcolorbox")
14+
)
15+
inject(
16+
usePackage("fontawesome")
1417
)
1518
inject(
1619
"\\definecolor{quarto-callout-color}{HTML}{" .. kColorUnknown .. "}\n" ..

0 commit comments

Comments
 (0)