Skip to content

Commit

Permalink
Improve table embed support (progress on #7210)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonstyle committed Oct 14, 2023
1 parent 6f586c3 commit a746006
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/resources/filters/customnodes/floatreftarget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -615,14 +615,15 @@ end, function(float)
end
return pandoc.Para({imgEl})
elseif float.in_code_cell_output then

-- If the float is in a code_cell_output, it is ok to drop the identifier
-- and caption, because that infdormation is still carried by the cell itself
return float.content

else
return pandoc.Figure(
{float.content},
{float.caption_long},
float.identifier)
-- TODO: Consider just putting together list of paragraphs
--
return float.content
end
end)

Expand Down
22 changes: 22 additions & 0 deletions src/resources/filters/quarto-post/ipynb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,32 @@ function ipynb()
-- if we are in source notebook mode, we need to omit identifiers that appear on images
-- and instead allow the cell yaml to declare things like ids
if produceSourceNotebook and el.attr.classes:includes('cell-output-display') then

-- First, we need to collapse tables that are surrounded by
-- raw blocks (which specifically addresses tables that are parsed and
-- surrounded by rawblocks to contain unparseable content)
-- This will catch GT tables and render HTML and markdown versions.
if #el.content == 3 and el.content[1].t == "RawBlock" and el.content[2].t == "Table" and el.content[3].t == "RawBlock" then
if el.content[1].format == "html" and el.content[3].format == "html" then

local tbl = pandoc.Pandoc(el.content[2])
local htmlRenderedTbl = pandoc.write(tbl, "html")
local htmlRawBlock = pandoc.RawBlock("html", el.content[1].text .. htmlRenderedTbl .. el.content[3].text)

local mdRenderedTbl = pandoc.write(tbl, "markdown")
local mdRawBlock = pandoc.RawBlock("markdown", mdRenderedTbl)

el.content = pandoc.Blocks({htmlRawBlock, mdRawBlock})
end
end

el = _quarto.ast.walk(el, {
Image = function(imgEl)
imgEl.attr = pandoc.Attr()
return imgEl
end,
FloatRefTarget = function(float)

end,
Table = function(tbl)
local rendered = pandoc.write(pandoc.Pandoc(tbl), "markdown")
Expand Down
37 changes: 37 additions & 0 deletions tests/docs/smoke-all/embed/tables/inset-table.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: "Notebook"
format:
ipynb:
notebook-preserve-cells: true
produce-source-notebook: true
citeproc: false
---

```{r}
#| label: tbl-one
#| tbl-cap: This is a kable table
library(knitr)
kable(head(mtcars))
```

```{r}
#| label: tbl-two
#| tbl-cap: This is a gt table
library(gt)
gt(head(mtcars))
```


```{r}
#| label: tbl-three
#| tbl-cap: This is a flextable table
library(flextable)
flextable(head(mtcars))
```




9 changes: 9 additions & 0 deletions tests/docs/smoke-all/embed/tables/parent.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Test of embedding tables"
format:
html:
toc: true
---

{{< embed inset-table.qmd#tbl-three >}}

0 comments on commit a746006

Please sign in to comment.