Coverage for src/prosemark/freewriting/adapters/title_handler.py: 100%
11 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-09-24 18:08 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-09-24 18:08 +0000
1"""Title processing utilities for freewriting feature.
3This module provides utilities for processing and sanitizing titles
4for use in freewriting sessions, including length handling and
5character sanitization.
6"""
8from __future__ import annotations
11def process_title(title: str, max_length: int = 50) -> str:
12 """Process a title for use in freewriting sessions.
14 Args:
15 title: The raw title string to process.
16 max_length: Maximum allowed length for the processed title.
18 Returns:
19 Processed title, truncated if necessary with ellipsis.
21 """
22 if not title:
23 return title
25 # Strip whitespace
26 processed = title.strip()
28 # Truncate if too long
29 if len(processed) > max_length:
30 processed = processed[: max_length - 3] + '...'
32 return processed
35def sanitize_title_for_filename(title: str) -> str:
36 """Sanitize a title for safe use in filenames.
38 Args:
39 title: The title string to sanitize.
41 Returns:
42 Sanitized title safe for use in filenames.
44 """
45 # Use the FileSystemAdapter's sanitize method
46 from prosemark.freewriting.adapters.file_system_adapter import FileSystemAdapter
48 return FileSystemAdapter.sanitize_title(title)