Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.44k stars 280 forks source link

Title case filter with apostrophe - Capitalize issue #771

Closed magikstm closed 1 year ago

magikstm commented 1 year ago

With this input: {{ "Steiner's theorem" | title }}

Current result is: Steiner'S Theorem

Expected result is: Steiner's Theorem

First mentioned here: https://zola.discourse.group/t/title-case-filter-with-apostrophes/1526

Can be reproduced here: https://tera.netlify.app/playground/

magikstm commented 1 year ago

I have a fix and a test case for it.

I'll submit a PR.

eh8 commented 1 year ago

@magikstm Nice work!

I will add that the current title filter indiscriminately capitalizes every word in the input. I can't speak for languages other than English, but there are certain words which should not be capitalized in a title.

i.e.

{{ "Examining Steiner's theorem and its consequences for physics" | title }}

should yield

Examining Steiner's Theorem and Its Consequences for Physics

For reference, this is a Javascript implementation of a titlecase function that considers these edge cases.

magikstm commented 1 year ago

@eh8

Adding a similar feature as the linked javascript: var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|v.?|vs.?|via)$/i

Would be out of scope of the current feature.

I'm unsure if it should be added or not. It's only in english and it is "opiniated" on which words are or aren't capitalized.

Keats commented 1 year ago

Yeah, let's not add something English-specific. If people want that, they can add their own for their language.