Python port of John Gruber's titlecase.pl for intelligent title case conversion with style guide compliance
Overall
score
79%
A utility that converts text strings into proper title case format following journalistic style guidelines.
@generates
Converts strings to title case where most words are capitalized, but certain small words remain lowercase when they appear in the middle of the title.
Ensures the first and last words of a title are always capitalized, even if they are typically considered small words.
Capitalizes words that follow subphrase punctuation like colons, question marks, and exclamation marks.
def format_title(text: str) -> str:
"""
Converts a text string to title case following journalistic style guidelines.
Small words (a, an, and, as, at, but, by, en, for, if, in, of, on, or,
the, to, v, v., via, vs, vs.) are kept lowercase when they appear in the
middle of the title. The first and last words are always capitalized.
Words following colons, question marks, exclamation marks, and similar
punctuation are capitalized.
Args:
text: The input string to convert to title case
Returns:
The text converted to proper title case format
Examples:
format_title("this is a test")
# Returns: "This Is a Test"
format_title("question: what happens?")
# Returns: "Question: What Happens?"
"""
passProvides title case conversion functionality following style guide rules.
@satisfied-by
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