Skip to content

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

@cderv

Description

@cderv

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingknitr

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions