Skip to content

Commit

Permalink
Merge pull request #7829 from quarto-dev/knitr-eng-sql-wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv authored Dec 8, 2023
2 parents 45a830e + cf3ed4e commit 218e03d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/changelog-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
- ([#6792](https://github.com/quarto-dev/quarto-cli/issues/6792)): `fig-asp` provided at YAML config level now correctly work to set `fig.asp` chunk option in **knitr**.
- ([#7002](https://github.com/quarto-dev/quarto-cli/issues/7002)): `layout-valign` is correctly forwarded to HTML to tweak vertical figure layout alignment for computational figures.
- ([#5994](https://github.com/quarto-dev/quarto-cli/issues/5994)): Options like `include` or `echo` for `ojs` or `mermaid` cells are now correctly handled with knitr engine.
- ([#4869](https://github.com/quarto-dev/quarto-cli/issues/4869)): `sql` cell output has now correct Quarto treatment so that specific features like `column: margin` works.

## OJS engine

Expand Down
3 changes: 3 additions & 0 deletions src/command/render/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ const kQuartoCustomFormat = "quarto-custom-format";
const kIsShinyPython = "is-shiny-python";
const kShinyPythonExec = "shiny-python-exec";

const kExecutionEngine = "execution-engine";

export async function filterParamsJson(
args: string[],
options: PandocOptions,
Expand Down Expand Up @@ -176,6 +178,7 @@ export async function filterParamsJson(
[kFormatIdentifier]: options.format.identifier,
[kIsShinyPython]: isShinyPython,
[kShinyPythonExec]: isShinyPython ? await pythonExec() : undefined,
[kExecutionEngine]: options.executionEngine,
};
return JSON.stringify(params);
}
Expand Down
7 changes: 7 additions & 0 deletions src/resources/filters/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import("./common/wrapped-filter.lua")
import("./quarto-init/configurefilters.lua")
import("./quarto-init/includes.lua")
import("./quarto-init/resourcerefs.lua")
import("./quarto-init/knitr-fixup.lua")

import("./quarto-post/render-asciidoc.lua")
import("./quarto-post/book.lua")
Expand Down Expand Up @@ -202,6 +203,12 @@ local quarto_init_filters = {
file_metadata(),
resourceRefs()
})},
{ name = "init-knitr-syntax-fixup", filter = filterIf(
-- only do those fix-up when we know computation engine was knitr
function() return param("execution-engine") == "knitr" end,
knitr_fixup()
)
},
}

-- v1.4 change: quartoNormalize is responsible for producing a
Expand Down
14 changes: 14 additions & 0 deletions src/resources/filters/quarto-init/knitr-fixup.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
knitr_fixup = function()
return {
-- https://github.com/quarto-dev/quarto-cli/issues/4869
-- knitr:::eng_sql is badly design and escape our cell-output wrapping in R
-- so we need to fix it up here by detecting the <div> which will be seen as DIV because
-- we use +native_divs by default
Div = function(e)
if e.classes:includes("knitsql-table") then
return pandoc.Div(e.content, { class = "cell-output-display" })
end
return e
end
}
end
14 changes: 14 additions & 0 deletions tests/docs/smoke-all/knitr/check-output-display.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Pandoc = function(doc)
local found = false
doc.blocks:walk({
Div = function(div)
if div.classes:includes("cell-output-display") then
found = true
end
end
})
if not found then
error("Should have found a wrapping cell here")
crash_with_stack_trace()
end
end
22 changes: 22 additions & 0 deletions tests/docs/smoke-all/knitr/eng-sql.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: cell output display wrapping for sql engine
engine: knitr
format: html
filters:
- at: pre-quarto
path: check-output-display.lua
---

```{r}
#| echo: false
library(DBI)
con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(con, "mtcars", mtcars)
```

```{sql}
#| column: margin
#| connection: con
select cyl from mtcars limit 5
```

0 comments on commit 218e03d

Please sign in to comment.