-
DescriptionI'm trying to use a custom knitr engine to enter raw yaml in a chunk and output a raw typst string in a quarto document using the typst output format, but I'm a bit stumped with the output. It seems that the text is escaped, and I don't know how to turn that off. MRE:
Output:
Output I am hoping to get (no block container, and no escaping of characters):
So that typst processes it. When I switch to a different format, eg. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 23 replies
-
If you want to add/emit raw "whatever":
|
Beta Was this translation helpful? Give feedback.
-
knitr has a function to emit raw block - you should use it. out <- knitr::raw_block(glue::glue("#strong( [{ spec }] )"), "typst") Also in You already used Hope it helps ---
title: "Test"
format:
typst:
keep-typ: true
keep-md: true
---
```{r, echo=FALSE}
library(glue)
library(yaml)
library(knitr)
knitr::knit_engines$set(yamltypst = function(options) {
options[["results"]] <- "asis"
# get code together
code <- paste(options$code, collapse = '\n')
# parse
spec <- yaml::yaml.load(code)
# reset language for markdown highlighting
options$engine <- "yaml"
out <- knitr::raw_block(glue::glue("#strong( [{ spec }] )"), "typst")
knitr::engine_output(
options,
options$code,
out = out
)
})
```
## Quarto
Quarto enables you to weave together content and executable code into a finished document.
```{yamltypst}
stuff: yamlcontent
```
|
Beta Was this translation helpful? Give feedback.
-
Thanks, I hadn't seen that recent change.
True, I was mostly aiming for a proof of principle so I didn't wrap it in a package. I wish there was a way to specify a "setup" file in the YAML header, if just to load a set of packages. Something like
Yep, cat() is the route I initially took (without wrapping it as an extension), and I had the filename specified in the YAML for more flexibility:
Yes, I think this is the best option, so I'm hoping to try it at some point. Unfortunately the Lua side of things is always a bit of a barrier :/
Thanks! Credits should go to PgSuper who wrote the table code; I merely tweaked it and wrapped it up. |
Beta Was this translation helpful? Give feedback.
knitr has a function to emit raw block - you should use it.
Also in
```{yamltypst, echo=FALSE, asis=TRUE}
, theasis
option is not a known knitr options.You already used
options[["results"]] <- "asis"
in your engine, so it should be enough.Hope it helps