A Quarto extension that automatically extracts code blocks from your documents and splits them by programming language into separate, executable script files.
To install the ripper Quarto extension, follow these steps:
- Open your terminal.
- Execute the following command:
quarto add coatless-quarto/ripperThis command will download and install the Quarto extension under the _extensions subdirectory of your Quarto project. If you are using version control, ensure that you include this directory in your repository.
Add the ripper filter to your document's YAML front matter:
---
title: "My Analysis"
filters:
- ripper
---
```{r}
data <- mtcars
summary(data)
```
```{python}
import pandas as pd
df = pd.DataFrame({"x": [1, 2, 3]})
```Render your document with Quarto:
quarto render my-analysis.qmdExtracted scripts will be created in the same directory with names based on your document file name, e.g.
my-analysis.R- All R code extractedmy-analysis.py- All Python code extracted
Links to the generated script files will be included in your rendered document under a "Script file(s)" section or at a custom location if specified.
Ripper supports multiple global options under extensions.ripper:
---
echo: true # Required to include code blocks in output
filters:
- ripper
extensions:
ripper:
include-yaml: true # Include YAML as comments (default: true)
script-links-position: "bottom" # Position of links section (default: "bottom")
output-name: "my-scripts" # Custom base name for output files (optional)
debug: false # Enable verbose logging (default: false)
---true(default): Includes YAML frontmatter as commented lines at the top of each scriptfalse: Extracts only code with no YAML comments
Controls where the "Script file(s)" section with links to generated scripts appears:
"bottom"(default): Places the section at the end of the document"top": Places the section at the beginning of the document"custom": Places the section where you define a Div with#ripper-linksin your document"none": Suppresses the section entirely
- To place the section at a specific location in your document, use
script-links-position: "custom"and add a Div with the id#ripper-links.
---
title: "My Analysis"
filters:
- ripper
extensions:
ripper:
script-links-position: "custom"
---
## Introduction
Some introductory text here.
::: {#ripper-links}
:::
## Analysis
```{r}
# Your code here
```- Allows you to specify a custom base name for the generated script files instead of using the document name.
- For example, if you set
output-name: "my-custom-name", renderingmy-analysis.qmdwould produce:my-custom-name.Rmy-custom-name.py
- Enables verbose logging to help troubleshoot issues or understand the extension's behavior.
16 languages supported with appropriate file extensions and comment styles:
| Language | Extension | Comment |
|---|---|---|
| R | .R | #' |
| Python | .py | #' |
| Julia | .jl | #' |
| Bash | .sh | #' |
| JavaScript | .js | //' |
| TypeScript | .ts | //' |
| SQL | .sql | --' |
| Rust | .rs | //' |
| Go | .go | //' |
| C++ | .cpp | //' |
| C | .c | //' |
| Java | .java | //' |
| Scala | .scala | //' |
| Ruby | .rb | #' |
| Perl | .pl | #' |
| PHP | .php | //' |
- sorting-hat: Conditionally retain or omit code blocks by language in rendered documents.
- Use with ripper to control what appears in your document while extracting all visible code to scripts.
- regurgitate: Automatically create code appendices in your rendered document, organized by language or document order.
- Complements ripper by providing in-document code listings while ripper creates external executable files.
Ripper's ability to extract code from Quarto documents originated a feature request I submitted in
quarto-dev/quarto-cli issue #1156 back on June 14, 2022.