https://github.com/insightsengineering/pattern-strip
Pattern Strip Extension For Quarto
https://github.com/insightsengineering/pattern-strip
r
Last synced: about 1 month ago
JSON representation
Pattern Strip Extension For Quarto
- Host: GitHub
- URL: https://github.com/insightsengineering/pattern-strip
- Owner: insightsengineering
- License: other
- Created: 2024-02-26T15:02:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-15T16:05:19.000Z (about 2 years ago)
- Last Synced: 2025-05-19T23:43:52.664Z (about 1 year ago)
- Topics: r
- Language: Lua
- Homepage: https://insightsengineering.github.io/pattern-strip/
- Size: 3.91 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pattern Strip Extension For Quarto
This is a Quarto extension that provides a filter to remove text from a string using a [Lua's patterns](https://www.lua.org/manual/5.4/manual.html#6.4.1) (similar to regular expressions but not exactly the same). This is applied on the `CodeBlock` only.
The main goal of this extension is to remove certain comments from the code blocks. For example, comments that are used for linters (`# nolint`) or styler (`# styler: off`).
This extension is not limited to R code blocks only, it can be used for any code block.
For R, similar functionality can be achieved using `tidy` chunk option (source). This however, is applicable for single article / code chunk only and it is not possible to specify globally in the `_quarto.yml` file. This extension aims to address these limitations and provide more general solution applicable for not only R code blocks.
Related discussions:
*
*
## Installing
```bash
quarto install extension insightsengineering/pattern-strip
```
This will install the extension under the `_extensions` subdirectory.
If you're using version control, you will want to check in this directory.
## Using
In your `_quarto.yml` file, please (i) add the extension and (ii) specify the patterns to remove. For example:
```yaml
filters:
- pattern-strip
pattern-strip-patterns:
- "#%s?nolint.*"
- "#%s?styler:.*"
- ...
```
Lua patterns does not support alteration operator therefore patterns needs to be specified in a list [(source)](https://stackoverflow.com/questions/10438358/what-is-the-alternation-operator-in-lua-patterns).
## Example
Here is the source code for a minimal example: [example.qmd](example.qmd).