Skip to content

Commit

Permalink
Merge pull request #9012 from quarto-dev/knitr/ipynb-detection
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv authored Mar 8, 2024
2 parents b222df5 + 6539af8 commit 0b11aa2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
3 changes: 2 additions & 1 deletion news/changelog-1.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ All changes included in 1.5:

## Shortcodes

- ([#8316](https://github.com/quarto-dev/quarto-cli/issues/8316)): Add fallback value for the `env` shortcode
- ([#8316](https://github.com/quarto-dev/quarto-cli/issues/8316)): Add fallback value for the `env` shortcode.
- ([#9011](https://github.com/quarto-dev/quarto-cli/issues/9011)): `embed` shortcode now renders the embedded document without error when it is using knitr engine and have some outputs with HTML dependencies.

## Lightbox Images

Expand Down
15 changes: 13 additions & 2 deletions src/resources/rmd/execute.R
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ is_pandoc_latex_output <- function(format) {
is_pandoc_to_format(format, c("latex", "beamer", "pdf"))
}

is_pandoc_ipynb_output <- function(format) {
is_pandoc_to_format(format, c("ipynb"))
}

# check if pandoc$to is among markdown outputs
is_pandoc_markdown_output <- function(format) {
markdown_formats <- c(
Expand All @@ -593,9 +597,16 @@ is_pandoc_markdown_output <- function(format) {
is_pandoc_to_format(format, markdown_formats)
}

# `prefer-html: true` can be set in markdown format that supports HTML outputs
# should be equivalent of TS function:
# isHtmlCompatible() in src/config/format.ts
is_html_prefered <- function(format) {
is_pandoc_markdown_output(format) && isTRUE(format$render$`prefer-html`)
# `prefer-html: true` can be set in markdown format that supports HTML outputs
(
is_pandoc_markdown_output(format) &&
isTRUE(format$render$`prefer-html`)
) ||
# this could happen when using embed shortcode which convert to ipynb output format.
is_pandoc_ipynb_output(format)
}

is_dashboard_output <- function(format) {
Expand Down
14 changes: 11 additions & 3 deletions tests/docs/smoke-all/embed/tables/inset-table.qmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "Notebook"
html-table-processing: none # TODO: To fix in #8927
format:
ipynb:
notebook-preserve-cells: true
Expand All @@ -8,15 +9,15 @@ format:
---

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

```{r}
#| label: tbl-two
#| label: tbl-gt
#| tbl-cap: This is a gt table
library(gt)
Expand All @@ -25,13 +26,20 @@ gt(head(mtcars))


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


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


27 changes: 26 additions & 1 deletion tests/docs/smoke-all/embed/tables/parent.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,32 @@ title: "Test of embedding tables"
format:
html:
toc: true
_quarto:
tests:
html:
ensureHtmlElements:
-
- '#kable .quarto-embed-nb-cell #tbl-kable .cell-output-display > *'
# TODO: requires html-table-processing: none in embed file - fix #8927
- '#gt .quarto-embed-nb-cell #tbl-gt .cell-output-display > *'
- '#flextable .quarto-embed-nb-cell #tbl-flextable .cell-output-display > *'
# TODO: requires html-table-processing: none in embed file - fix #8927
- '#kable-extra .quarto-embed-nb-cell #tbl-kable-extra .cell-output-display > *'
---

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

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

# with GT {#gt}

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

# with flextable {#flextable}

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

# with kableExtra {#kable-extra}

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

0 comments on commit 0b11aa2

Please sign in to comment.