-
Notifications
You must be signed in to change notification settings - Fork 24
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
Provide a helper function to create metadata yaml block in document body #137
Comments
More thoughts: I wonder if we could make that more transparent and internal to Quarto so that a user would not have to write the meta value. Same way a user don't have to write the HTML dependencies in header - knitr and quarto will do it. We could maybe leverage the POC of what could work to write all meta collected at once---
title: "Some title"
format: html
keep-md: true
---
Example of helpers
```{r}
as_quarto_meta <- function(meta) {
yaml_quarto_meta <- structure(meta, class = "quarto_yaml_meta")
knitr::asis_output(list(), meta = list(yaml_quarto_meta))
}
```
Computing a value in R
```{r}
admin <- TRUE
```
Setting it as a meta to us
```{r}
# add meta
as_quarto_meta(list(admin = admin))
```
Is this document for admin: {{< meta admin >}}
::: {.content-visible when-meta="admin"}
If so, then this should be visible as it is only `when-meta="admin"`
:::
::: {.content-hidden when-meta="admin"}
Hum... It seems you are not admin..
:::
```{r}
as_quarto_meta(list(userid = "abc"))
```
simulate quarto rendering to handle knit_meta as rmarkdown would handle latex dependencies and html dependencies
```{r}
write_meta <- function() {
quarto_meta <- rmarkdown:::knit_meta_reset("quarto_yaml_meta")
if (!length(quarto_meta)) return()
handlers <- list(logical = function(x) {
value <- ifelse(x, "true", "false")
structure(value, class = "verbatim")
})
res <- yaml::as.yaml(unlist(quarto_meta, recursive = FALSE), handlers = handlers)
knitr::asis_output(paste0("---\n", res, "---\n"))
}
write_meta()
```
Integrating this logic in Quarto directly would not pass by a writing on meta as yaml in the doc, but would be passed directly to quarto... Not sure it worth it - only if we want to have the exact same logic maybe in jupyter if similar tooling as HTML deps come out one day 🤔 |
See rich-iannone/quarto-email#9 for a prime use case, but smoothing out these edges will be relevant beyond conditional emails. |
@rich-iannone can you look at the POC idea above (#137 (comment)) ? I believe the function offered would solve the issue right ? this R package quarto could provide a function to write simply any list as a YAML block in Markdown, but I wonder if the meta idea could be even better for user experience. Even quarto itself could retrieve the meta defined by any R function and do the YAML metadata addition. We can discuss live too. Thanks |
Listing another usage of this: A good workflow to provide a solution in Quarto for previous Example: |
Related to #160
cc @kmasiello
Example
This is quite long to write, so it could use a helper
Using inline R code
Or using a cell with option
Food for thoughts...
The text was updated successfully, but these errors were encountered: