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

1"""Title processing utilities for freewriting feature. 

2 

3This module provides utilities for processing and sanitizing titles 

4for use in freewriting sessions, including length handling and 

5character sanitization. 

6""" 

7 

8from __future__ import annotations 

9 

10 

11def process_title(title: str, max_length: int = 50) -> str: 

12 """Process a title for use in freewriting sessions. 

13 

14 Args: 

15 title: The raw title string to process. 

16 max_length: Maximum allowed length for the processed title. 

17 

18 Returns: 

19 Processed title, truncated if necessary with ellipsis. 

20 

21 """ 

22 if not title: 

23 return title 

24 

25 # Strip whitespace 

26 processed = title.strip() 

27 

28 # Truncate if too long 

29 if len(processed) > max_length: 

30 processed = processed[: max_length - 3] + '...' 

31 

32 return processed 

33 

34 

35def sanitize_title_for_filename(title: str) -> str: 

36 """Sanitize a title for safe use in filenames. 

37 

38 Args: 

39 title: The title string to sanitize. 

40 

41 Returns: 

42 Sanitized title safe for use in filenames. 

43 

44 """ 

45 # Use the FileSystemAdapter's sanitize method 

46 from prosemark.freewriting.adapters.file_system_adapter import FileSystemAdapter 

47 

48 return FileSystemAdapter.sanitize_title(title)