Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added wordcount filter #649

Merged
merged 3 commits into from
Nov 28, 2024
Merged

added wordcount filter #649

merged 3 commits into from
Nov 28, 2024

Conversation

jqnatividad
Copy link
Contributor

No description provided.

@yacir
Copy link
Contributor

yacir commented Nov 25, 2024

Nice!
However, I noticed that the implementation doesn’t fully match the Jinja2 result.

Using split_whitespace might fail, as Jinja2 relies on the \w+ regex. Here’s an example of a mismatched result:

{{'hello-world'|wordcount}} # -> 2
{{'hello@world'|wordcount}} # -> 2
"{}", "hello-world'".split_whitespace().count() // -> 1
"{}", "hello@world'".split_whitespace().count() // -> 1

by manually implementing the `\w+` regex, as we don't want an external dependency on regex crate
@jqnatividad
Copy link
Contributor Author

jqnatividad commented Nov 25, 2024

Thanks @yacir for catching that as I just went for the naive implementation and didn't check Jinja2.

@mitsuhiko mitsuhiko merged commit 11f89a2 into mitsuhiko:main Nov 28, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants