-
Notifications
You must be signed in to change notification settings - Fork 331
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
include does not inject code into a non-executable block #1237
Comments
Thanks! I can repro this locally. |
The "issue" here is that shortcodes are currently only detected as "standalone" markdown constructs. This is admittedly bad, but I'm concerned about changing this ahead of v1.0. It's not the only problem with shortcodes, either. A related problem happens, for example, if we try including from inside a bulleted list:
The result looks like so: This happens because our detection of shortcodes is not syntax-aware, and doesn't know to expand the file by including the bulleted list indentation. |
Codes like |
Those definitely should be working in code blocks (here we specifically look for them: https://github.com/quarto-dev/quarto-cli/blob/main/src/resources/filters/quarto-pre/shortcodes.lua#L14). If they don't work its a regression we need to fix for v1.0 (as we currently use that in the quarto website and RS Workbench docs) |
@aronatkins These do work in static/display code blocks (i.e. non-executable) but they don't work for executable code blocks (and they will likely not ever work inside executable blocks). |
Note that knitr already has a native feature for specifying the contents of code chunk from an external file ( |
One line we don't want to cross is allowing content in code chunks/cells that is not syntactically valid for the language (which in turn prevents cell-by-cell execution in RStudio, VS Code, Jupyter Lab, etc.) |
Thanks @jjallaire - I've confirmed that shortcodes like In case others have similar problems: My workaround to have code examples included in plain code blocks is to use the ---
title: embedded example
engine: knitr
---
```{embed, file = "environ.R"}
```
To have values available throughout the document, I am currently using environment variables, as they can be accessed in code (using language-specific techniques), in prose, in YAML fields, etc. ---
title: "Going {{< env HOME >}}"
engine: knitr
---
It is so nice to go {{< env HOME >}}
Using environment variables in code blocks using language-specific references:
```{bash}
echo "${HOME}"
```
```{r}
cat(Sys.getenv("HOME"))
```
Environment variables in code blocks (not executable):
```r
echo "{{< env HOME >}}"
``` |
For those looking for a workaround: in julia you can use the following to include the content of source files (similar should work for other languages):
|
@cscheid - this issue needs to be reopened; |
As a stopgap we created this extension: https://github.com/quarto-ext/include-code-files But yes, we do need to make this work (and also create a built-in feature similar to what the extension does) |
The reason we haven't easily resolved for include specifically is that the include shortcode resolution happens in typescript, before Pandoc. Other shortcodes like meta, var, etc, happen in Lua. We need to add include processing to Lua in one shape or another, but this is trickier than it looks. We need to be aware of a number of issues (making sure that paths etc are resolved identically in Lua and Typescript). It's also going to be the case that a "Lua {{< include >}}" will behave differently than a typescript one out of necessity (in Typescript, we can create includes that break syntactic boundaries; in Lua, that won't be the case). This is going to be potentially confusing for users. I wonder if we should have different names for each. |
I think we discussed having |
I have successfully used the https://github.com/quarto-ext/include-code-files filter in a revealjs presentation. Thanks for the pointer. |
Bug description
Using Quarto 0.9.607 (contained in a recent RStudio build -- 2022.10.0 Build 9), but have also tested Quarto 0.9.629. The same rendered results occur with both versions, and within and outside the RStudio IDE.
Observed on macOS Monterey - 12.4
Given
index.qmd
defined as:and a
cats.R
file defined as:cat("cats!\n")
The rendering should present the code from
cats.R
as formatted R code in the first code block (containing theinclude
).Instead, the rendered result has an empty code block and looks like:
Checklist
quarto check
in a terminal in your issue?The text was updated successfully, but these errors were encountered: