Skip to content

[feature] Add regex_replace filter for Jinja2 to allow for notification formatting #3501

@troymccabe

Description

@troymccabe

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 <td>thing</td><td>other</td><td>field</td> 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, I'll add the filter and register it with jinja
  2. in forms.py#ValidateJinja2Template, add the filter so validation passes

If this looks correct, I'll give it a crack

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions