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

[knitr] custom engine setting asis output does not remove all divs #9184

Open
cderv opened this issue Mar 25, 2024 · 0 comments
Open

[knitr] custom engine setting asis output does not remove all divs #9184

cderv opened this issue Mar 25, 2024 · 0 comments
Assignees
Labels
bug Something isn't working knitr
Milestone

Comments

@cderv
Copy link
Collaborator

cderv commented Mar 25, 2024

Here is a demo of using a custom engine in knitr which is meant to output raw content. (More details at #9163).
So the engine sets output: asis internally (results: asis in knitr context)

---
title: "Test"
format: 
  typst:
    keep-typ: true
    keep-md: true
---

```{r, echo=FALSE}
knitr::knit_engines$set(demo = function(options) {

    options[["results"]] <- "asis"

    knitr::engine_output(
      options,
      options$code,
      out = "Should be `asis` content."
    )
  })
```

## Quarto

Quarto enables you to weave together content and executable code into a finished document.

```{demo}
Do no matter
```

This is the intermediate .md

::: {.cell}

```{.demo .cell-code}
Do no matter
```


Should be `asis` content.
:::

The output wrapping is correctly removed (i.e ::: {.cell-output .cell-output-stdout} and fenced code block.

However ::: {.cell} is still there.

In code base, we decide to add the wrapping div on condition

# if there is a label, additional classes, a forwardAttr, or a cell.cap
# then the user is deemed to have implicitly overridden results = "asis"
# (as those features don't work w/o an enclosing div)
needCell <- isTRUE(nzchar(label)) ||
length(classes) > 1 ||
isTRUE(nzchar(forwardAttr)) ||
isTRUE(nzchar(cell.cap))
if (identical(options[["results"]], "asis") && !needCell) {
x
} else {
paste0(
options[["indent"]], "::: {",
labelId(label), paste(classes, collapse = " ") ,forwardAttr, "}\n", x, "\n", cell.cap ,
options[["indent"]], ":::"
)
}

But this is done in the chunk hook - and in fact knitr does not get the modified options from cell at this point. It could be an issue from knitr itself.

For now, it means that output: asis needs to explicitly be set on a cell that should not have the output div.

@cderv cderv added the knitr label Mar 25, 2024
@cderv cderv self-assigned this Mar 25, 2024
@mcanouil mcanouil added the bug Something isn't working label Apr 11, 2024
@cscheid cscheid added this to the Future milestone Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working knitr
Projects
None yet
Development

No branches or pull requests

3 participants