Skip to content

Commit

Permalink
Merge pull request #10865 from quarto-dev/bugfix/10858
Browse files Browse the repository at this point in the history
floatreftarget,gfm - don't crash when pandoc.utils.type(float.content) == 'Blocks'
  • Loading branch information
cscheid authored Sep 23, 2024
2 parents 66b276e + 20acb2c commit d854676
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
1 change: 1 addition & 0 deletions news/changelog-1.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All changes included in 1.6:
- ([#10196](https://github.com/quarto-dev/quarto-cli/issues/10196)): Protect against nil values in `float.caption_long`.
- ([#10328](https://github.com/quarto-dev/quarto-cli/issues/10328)): Interpret subcells as subfloats when subcap count matches subcell count.
- ([#10624](https://github.com/quarto-dev/quarto-cli/issues/10624)): Don't crash when proof environments are empty in `pdf`.
- ([#10858](https://github.com/quarto-dev/quarto-cli/issues/10858)): Don't crash in `gfm` when `content` of a `FloatRefTarget` is of type `Blocks`.

## `dashboard` Format

Expand Down
36 changes: 23 additions & 13 deletions src/resources/filters/customnodes/floatreftarget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1045,23 +1045,33 @@ end, function(float)

local open_block = pandoc.RawBlock("markdown", "<div id=\"" .. float.identifier .. "\">\n")
local close_block = pandoc.RawBlock("markdown", "\n</div>")
local result = pandoc.Blocks({open_block})
local insert_content = function()
if pandoc.utils.type(float.content) == "Block" then
result:insert(float.content)
else
result:extend(quarto.utils.as_blocks(float.content))
end
end
local insert_caption = function()
if pandoc.utils.type(float.caption_long) == "Block" then
result:insert(float.caption_long)
else
result:insert(pandoc.Plain(quarto.utils.as_inlines(float.caption_long)))
end
end

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

_quarto.ast.add_renderer("FloatRefTarget", function(_)
Expand Down
17 changes: 17 additions & 0 deletions tests/docs/smoke-all/2024/09/23/issue-10858.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: "Test"
format: gfm
---

::: {#fig-line-plot}

```python
import matplotlib.pyplot as plt
plt.plot([1,23,2,4])
plt.show()
```

Some output

A line plot
:::

0 comments on commit d854676

Please sign in to comment.