dgtlmoon / dgtlmoon/changedetection.io
[feature] Add `regex_replace` filter for Jinja2 to allow for notification formatting
- Dominant language
- Python
- Stars
- 34.1k
- Forks
- 2k
- Avg merge
- 10h
- Merged PRs (30d)
- 61
Description
**Version and OS**
v0.50.21/ubuntu (docker)
**Is your feature request related to a problem? Please describe.**
This is a QoL feature, in that it allows for strong control around notification content. It allows for users to format output using regex to split parts of the diff
**Describe the solution you'd like**
I'd like a `regex_replace` filter to be added to the Jinja registration. It looks like this is pretty highly requested of the Jinja team themselves, but there's hesitance to do so. Other projects have built their own filters to handle this specific situation
**Describe the use-case and give concrete real-world examples**
My diff is a single line of text (the html is a single line), and I'd like to extract `thingotherfield` into:
```
ThingLabel: thing
OtherLabel: other
FieldLabel: field
```
**Additional context**
This has been requested before, and is a middle-ground between a full-fledged "output gonkulator" and nothing. Previous requests: #2653 & #2000
I'm more than happy to raise a PR, but I wanted to get alignment before going through the testing. My plan is:
1. in [safe_jinja.py](https://github.com/dgtlmoon/changedetection.io/blob/master/changedetectionio/safe_jinja.py), I'll add the filter and register it with jinja
2. in [forms.py#ValidateJinja2Template](https://github.com/dgtlmoon/changedetection.io/blob/master/changedetectionio/forms.py#L484C7-L484C29), add the filter so validation passes
If this looks correct, I'll give it a crack
Contributor guide
Assessment
This issue has not been assessed yet.