quarto-ext / include-code-files Goto Github PK
View Code? Open in Web Editor NEWQuarto extension to include code from source files.
License: MIT License
Quarto extension to include code from source files.
License: MIT License
This example document contains two "include" instances; the first instance includes the referenced file as expected. The second instance adds the {.yaml include = "stuff.yml"}
text in the document.
---
title: includes
filters:
- include-code-files
---
```{.yaml include="stuff.yml"}
```
```{.yaml include = "stuff.yml"}
```
I ended up with whitespace surrounding the equals sign because I was trying to adapt some of the knitr embed/verbatim examples; those use whitespace.
Renders as:
Using Quarto 1.2.335.
I'm not sure what I'm supposed to be doing but the instructions as given on the README.md don't work for me.
~/github/bob-carpenter/stan-getting-started (main)$ quarto add quarto-ext/include-code-files
Quarto extensions may execute code when documents are rendered. If you do not
trust the authors of the extension, we recommend that you do not install or
use the extension.
? Do you trust the authors of this extension (Y/n) › Yes
[✓] Downloading
[✓] Unzipping
Found 1 extension.
The following changes will be made:
Include Code Files [Install] 1.0.0 (filter)
? Would you like to continue (Y/n) › Yes
[✓] Extension installation complete.
Learn more about this extension at https://www.github.com/quarto-ext/include-code-files
And then I put this in my Yaml:
filters:
- include-code-filters
and then I run and it fails with this message when doing the final rendering:
Error running filter /Applications/quarto/share/filters/main.lua:
Error running filter /Users/bcarpenter/github/bob-carpenter/stan-getting-started/quarto/include-code-filters:
Could not find executable /Users/bcarpenter/github/bob-carpenter/stan-getting-started/quarto/include-code-filters
stack traceback:
/Applications/quarto/share/filters/main.lua:4026: in function </Applications/quarto/share/filters/main.lua:4005>
[C]: in ?
[C]: in method 'walk'
/Applications/quarto/share/filters/main.lua:171: in function 'run_emulated_filter'
/Applications/quarto/share/filters/main.lua:449: in local 'callback'
/Applications/quarto/share/filters/main.lua:454: in upvalue 'run_emulated_filter_chain'
/Applications/quarto/share/filters/main.lua:495: in function </Applications/quarto/share/filters/main.lua:476>
stack traceback:
/Applications/quarto/share/filters/main.lua:171: in function 'run_emulated_filter'
/Applications/quarto/share/filters/main.lua:449: in local 'callback'
/Applications/quarto/share/filters/main.lua:454: in upvalue 'run_emulated_filter_chain'
/Applications/quarto/share/filters/main.lua:495: in function </Applications/quarto/share/filters/main.lua:476>
make: *** [stan-getting-started.pdf] Error 1
After I run the install, I can't find the include-code-filters
anywhere on my OS.
While this filter does include codes from an External file, code-fold: true
or code-summary: "some text"
is not working for that code chunk (that includes the source code). A quick reproducible example is as follows,
test.py
# code from test.py
for name in ["Sam", "Jake"]:
print(f"Hello {name}!")
test.qmd
---
title: "Including Code"
format:
html:
code-fold: true
code-summary: "Python Code"
jupyter: python3
filters:
- include-code-files
---
## Python
```{.python include="test.py"}
```
```{python}
print("Hello World")
```
output
I am using Quarto version,
$ quarto --version
1.2.235
Thanks.
This is a great filter, thank you! I saw in the docs for the pandoc-include-code filter you've cited for inspiration that they have a snippet-mode feature, as well, so the line numbers in the referenced code can change without breaking the reference in the docs:
// start snippet wow
int main() {
printf("such performance");
}
// end snippet wow
This would be a great feature to enable in this extension. I'd offer to develop it myself, but I have no experience with Lua whatsoever. Thanks again for this extension, it's very useful as is.
Sometimes it's easier to construct the path to a file in code, for example:
model_path = here::here("my-code-file.stan")
in a quarto document.
Is it possible to have the include argument of a chunk evaluated?
```{.stan include=model_path}
```
doesn't appear to evaluate the variable model_path
correctly. Is there a syntax option to have this variable get evaluated to return the file path, and then have the path parsed correctly as normal?
I figures out some more details and according to your request from here quarto-dev/quarto-cli#4340 (comment) I will open this issue:
To get code highlighting in HTML AND PDF I have to include the code file with different path:
`
::: {.content-visible when-format="html"}
```{.c include="../code/test.c"}
```
:::
::: {.content-visible when-format="pdf"}
```{.c include="./code/test.c"}
```
:::
`
On this way I get the code highlighting in html and pdf.
I attached the complete test project.
GBSSG_Skripte_030_Physik.zip
Quarto Version: 1.2.334 with installed include-code-files extension.
Thank you very much for your help
regards
Mike
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.