Python port of John Gruber's titlecase.pl for intelligent title case conversion with style guide compliance
Overall
score
79%
Build a text formatting utility that can apply different capitalization rules to titles based on context. The utility should support both standard title case (where first and last words are always capitalized) and relaxed title case (where small words can remain lowercase even at the beginning or end).
Your utility should provide a function format_title(text, capitalize_first_last=True) that:
capitalize_first_last=True (default), always capitalizes the first and last words regardless of whether they are small wordscapitalize_first_last=False, allows small words to remain lowercase even at the beginning or end of the titlecapitalize_first_last=True, returns "A Tale of Two Cities" @testcapitalize_first_last=False, returns "a Tale of Two Cities" @testcapitalize_first_last=True, returns "The Lord of the Rings" @testcapitalize_first_last=False, returns "the Lord of the Rings" @test@generates
def format_title(text: str, capitalize_first_last: bool = True) -> str:
"""
Format text as title case with configurable first/last word capitalization.
Args:
text: The input text to format
capitalize_first_last: If True, always capitalize first and last words.
If False, allow small words to remain lowercase.
Returns:
The formatted title string
"""
passProvides intelligent title case conversion following style guide rules.
Install with Tessl CLI
npx tessl i tessl/pypi-titlecasedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10