CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-titlecase

Python port of John Gruber's titlecase.pl for intelligent title case conversion with style guide compliance

Overall
score

79%

Overview
Eval results
Files

task.mdevals/scenario-1/

Title Case Formatter with Flexible First/Last Word Rules

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).

Requirements

Core Functionality

Your utility should provide a function format_title(text, capitalize_first_last=True) that:

  1. Converts text to title case following standard rules for small words
  2. When capitalize_first_last=True (default), always capitalizes the first and last words regardless of whether they are small words
  3. When capitalize_first_last=False, allows small words to remain lowercase even at the beginning or end of the title

Test Cases

  • Given the text "a tale of two cities", with capitalize_first_last=True, returns "A Tale of Two Cities" @test
  • Given the text "a tale of two cities", with capitalize_first_last=False, returns "a Tale of Two Cities" @test
  • Given the text "the lord of the rings", with capitalize_first_last=True, returns "The Lord of the Rings" @test
  • Given the text "the lord of the rings", with capitalize_first_last=False, returns "the Lord of the Rings" @test

Implementation

@generates

API

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
    """
    pass

Dependencies { .dependencies }

titlecase { .dependency }

Provides intelligent title case conversion following style guide rules.

Install with Tessl CLI

npx tessl i tessl/pypi-titlecase

tile.json