Skip to content

Commit 8b4d18a

Browse files
committed
[FIXME] Just want to try if this works
1 parent 4fb1c0a commit 8b4d18a

File tree

5 files changed

+70
-21
lines changed

5 files changed

+70
-21
lines changed

src/resources/filters/ast/customnodes.lua

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ function create_custom_node_scaffold(t, context)
243243
return result
244244
end
245245

246+
247+
local ptype = pandoc.utils.type
248+
local InlinesMT = getmetatable(pandoc.Inlines{})
249+
local BlocksMT = getmetatable(pandoc.Blocks{})
250+
246251
function create_emulated_node(t, tbl, context, forwarder)
247252
local result = create_custom_node_scaffold(t, context)
248253
tbl.t = t -- set t always to custom ast type
@@ -340,26 +345,27 @@ _quarto.ast = {
340345
end
341346
local node = node_accessor(table)
342347
local t = pandoc.utils.type(value)
343-
-- FIXME this is broken; that can only be "Block", "Inline", etc
344-
if t == "Div" or t == "Span" then
345-
local custom_data, t, kind = _quarto.ast.resolve_custom_data(value)
346-
if custom_data ~= nil then
347-
value = custom_data
348-
end
349-
end
348+
quarto_assert(t ~= 'Div' and t ~= 'Span', "")
350349
if index > #node.content then
351350
_quarto.ast.grow_scaffold(node, index)
352351
end
353-
local pt = pandoc.utils.type(node.content[index])
354-
if pt == "Block" then
355-
node.content[index].content =
356-
_quarto.modules.attribcheck.ensure_blocks(value)
357-
elseif pt == "Inline" then
358-
node.content[index].content =
359-
_quarto.modules.attribcheck.ensure_inlines(value)
352+
local inner_node = node.content[index]
353+
quarto_assert(inner_node ~= nil)
354+
if t == "Block" then
355+
inner_node.content = quarto.utils.as_blocks(value)
356+
elseif t == "Inline" then
357+
inner_node.content = quarto.utils.as_inlines(value)
360358
else
361-
warn('Cannot handle type ' .. pt)
362-
node.content[index].content = value
359+
local innertype = pandoc.utils.type(inner_node)
360+
if innertype == 'Block' then
361+
inner_node.content = quarto.utils.as_blocks(value)
362+
elseif innertype == 'Inline' then
363+
inner_node.content = quarto.utils.as_inlines(value)
364+
else
365+
warn('Cannot find the right content type for value ' .. t)
366+
warn(debug.traceback())
367+
inner_node.content = value
368+
end
363369
end
364370
end
365371
}

src/resources/filters/common/error.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ function fail(message, level)
1515
end
1616
end
1717

18-
function internal_error()
19-
fail("This is an internal error. Please file a bug report at https://github.com/quarto-dev/quarto-cli/", 5)
18+
function internal_error(msg, level)
19+
fail((msg and (msg .. '\n') or '') ..
20+
"This is an internal error. Please file a bug report at https://github.com/quarto-dev/quarto-cli/", level or 5)
21+
end
22+
23+
function quarto_assert (test, msg, level)
24+
if not test then
25+
internal_error(msg, level or 6)
26+
end
2027
end
2128

2229
function currentFile()

src/resources/filters/common/log.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ function warn(message, offset)
2020
io.stderr:write(lunacolors.yellow("WARNING (" .. caller_info(offset) .. ") " .. message .. "\n"))
2121
end
2222

23+
local orig_error = error
2324
function error(message, offset)
2425
io.stderr:write(lunacolors.red("ERROR (" .. caller_info(offset) .. ") " .. message .. "\n"))
2526
end
2627

2728
function fatal(message, offset)
2829
io.stderr:write(lunacolors.red("FATAL (" .. caller_info(offset) .. ") " ..message .. "\n"))
2930
-- TODO write stack trace into log, and then exit.
30-
crash_with_stack_trace()
31+
orig_error('FATAL QUARTO ERROR', offset)
3132
end
32-
-- luacov: enable
33+
-- luacov: enable

src/resources/filters/customnodes/callout.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,18 @@ function _callout_main()
260260
icon_color = "brand-color." .. callout_theme_color_map[callout.type]
261261
end
262262
end
263+
local function is_nonempty_node (node)
264+
return not not
265+
(node or
266+
(node.content and next(node.content)) or
267+
next(node))
268+
end
263269
if callout.attr.identifier == "" then
264270
return _quarto.format.typst.function_call("callout", {
265271
{ "body", _quarto.format.typst.as_typst_content(callout.content) },
266272
{ "title", _quarto.format.typst.as_typst_content(
267-
callout.title or pandoc.Plain(_quarto.modules.callouts.displayName(callout.type))
273+
(not is_nonempty_node(callout.title) and callout.title) or
274+
pandoc.Plain(_quarto.modules.callouts.displayName(callout.type))
268275
)},
269276
{ "background_color", pandoc.RawInline("typst", background_color) },
270277
{ "icon_color", pandoc.RawInline("typst", icon_color) },

src/resources/pandoc/datadir/_utils.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,34 @@ local function as_inlines(v)
295295
-- luacov: enable
296296
end
297297

298+
--- FIXME cleanup, make PR
299+
ensure_blocks = function (obj)
300+
local pt = ptype(obj)
301+
if pt == 'Blocks' then
302+
return obj
303+
elseif pt == 'List' or pt == 'table' then
304+
return setmetatable(obj, BlocksMT)
305+
elseif pt == 'Inline' then
306+
return setmetatable({pandoc.Plain{obj}}, BlocksMT)
307+
elseif pt == 'Inlines' then
308+
return setmetatable({pandoc.Plain(obj)}, BlocksMT)
309+
else
310+
return pandoc.Blocks(obj)
311+
end
312+
end
313+
314+
ensure_inlines = function (obj)
315+
local pt = ptype(obj)
316+
if pt == 'Inlines' then
317+
return obj
318+
elseif pt == 'List' or pt == 'table' then
319+
return setmetatable(obj, InlinesMT)
320+
else
321+
return pandoc.Inlines(obj)
322+
end
323+
end
324+
325+
298326
local function as_blocks(v)
299327
if v == nil then
300328
return pandoc.Blocks({})

0 commit comments

Comments
 (0)