Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua filter error with gfm for a crossref figure #10358

Closed
cderv opened this issue Jul 23, 2024 · 2 comments · Fixed by #10360
Closed

Lua filter error with gfm for a crossref figure #10358

cderv opened this issue Jul 23, 2024 · 2 comments · Fixed by #10360
Assignees
Labels
bug Something isn't working crossref lua Issues related to the lua codebase, filter chain, etc markdown Related to markdown-like output format
Milestone

Comments

@cderv
Copy link
Collaborator

cderv commented Jul 23, 2024

The following example throws an error on quarto 1.5.54

---
title: "Minimal example"
format: gfm
---

```{python}
#| label: fig-sin
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,1,10)
y = np.sin(x)

plt.plot(x,y)
```

The error is the following:

Error running filter /home/opt/quarto-1.5.54/share/filters/main.lua:
Block, list of Blocks, or compatible element expected, got table
        while retrieving function argument blocks
        while retrieving arguments for function Blocks
stack traceback:
        /home/opt/quarto-1.5.54/share/filters/main.lua:22460: in field 'render'
        /home/opt/quarto-1.5.54/share/filters/main.lua:1233: in local 'filter_fn'
        /home/opt/quarto-1.5.54/share/filters/main.lua:635: in function </home/opt/quarto-1.5.54/share/filters/main.lua:625>
        (...tail calls...)
        [C]: in ?
        [C]: in method 'walk'
        /home/opt/quarto-1.5.54/share/filters/main.lua:557: in function </home/opt/quarto-1.5.54/share/filters/main.lua:546>
        (...tail calls...)
        /home/opt/quarto-1.5.54/share/filters/main.lua:1334: in local 'callback'
        /home/opt/quarto-1.5.54/share/filters/main.lua:1352: in upvalue 'run_emulated_filter_chain'
        /home/opt/quarto-1.5.54/share/filters/main.lua:1388: in function </home/opt/quarto-1.5.54/share/filters/main.lua:1385>
stack traceback:
        /home/opt/quarto-1.5.54/share/filters/main.lua:557: in function </home/opt/quarto-1.5.54/share/filters/main.lua:546>
        (...tail calls...)
        /home/opt/quarto-1.5.54/share/filters/main.lua:1334: in local 'callback'
        /home/opt/quarto-1.5.54/share/filters/main.lua:1352: in upvalue 'run_emulated_filter_chain'
        /home/opt/quarto-1.5.54/share/filters/main.lua:1388: in function </home/opt/quarto-1.5.54/share/filters/main.lua:1385>

It sounds like it has something to do with the gfm output format, it works correctly if I render to html. The first time I encountered this bug I was rendering my project to both gfm and html, and changing that to just render html works as expected. I was using gfm because it gives a nice preview on GitHub.

Originally posted by @mbellitti in #9334 (comment)

@cderv cderv added bug Something isn't working markdown Related to markdown-like output format lua Issues related to the lua codebase, filter chain, etc labels Jul 23, 2024
@cderv
Copy link
Collaborator Author

cderv commented Jul 23, 2024

@cscheid I think this is a required follow up on

if caption_location == "top" then
return pandoc.Blocks({
open_block,
float.caption_long,
float.content,
close_block
})
else
return pandoc.Blocks({
open_block,
float.content,
pandoc.RawBlock("markdown", "\n"),
float.caption_long,
close_block
})
end
end)

We probably need to deal with float.caption_long the same way everywhere.

I see addition local to lightbox - should have a new helper to use everywhere ?

local function get_caption_content(floatEl)
if floatEl.caption_long then
return floatEl.caption_long.content or floatEl.caption_long
else
return pandoc.Inlines({})
end
end

Also sometimes, it seems with use pandoc.Inlines({}) as default

local caption_content = (float.caption_long and float.caption_long.content) or float.caption_long or pandoc.Inlines({})

And other time pandoc.Div({}), which then handle float.caption_long.content correctly. So not the same everywhere.

if float.caption_long == nil then
float.caption_long = pandoc.Div({})
end

and other place using already a helper as_blocks

pandoc.Div(quarto.utils.as_blocks(float.caption_long)),

Anyhow, handling a default works,

diff --git a/src/resources/filters/customnodes/floatreftarget.lua b/src/resources/filters/customnodes/floatreftarget.lua
index 913e7e5fc..6eb085535 100644
--- a/src/resources/filters/customnodes/floatreftarget.lua
+++ b/src/resources/filters/customnodes/floatreftarget.lua
@@ -1037,11 +1037,11 @@ end, function(float)
 
   local open_block = pandoc.RawBlock("markdown", "<div id=\"" .. float.identifier .. "\">\n")
   local close_block = pandoc.RawBlock("markdown", "\n</div>")

   if caption_location == "top" then
     return pandoc.Blocks({
       open_block,
-      float.caption_long,
+      float.caption_long or pandoc.Div({}),
       float.content,
       close_block
     })
@@ -1050,7 +1050,7 @@ end, function(float)
       open_block,
       float.content,
       pandoc.RawBlock("markdown", "\n"),
-      float.caption_long,
+      float.caption_long or pandoc.Div({}),
       close_block
     })
   end

but I am thinking maybe we should be sure to handle this everywhere needed. So assigning to you as you know better each part of FloatRefTarget

@cderv cderv added crossref triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. labels Jul 23, 2024
@cscheid cscheid added this to the Hot-fix milestone Jul 23, 2024
@cscheid cscheid removed the triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. label Jul 23, 2024
@cscheid
Copy link
Collaborator

cscheid commented Jul 23, 2024

The root cause of this is the upgrade to Pandoc where accessing the nodes no longer creates empty content. The fix is easy and I'll backport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crossref lua Issues related to the lua codebase, filter chain, etc markdown Related to markdown-like output format
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants