Coverage for src/prosemark/ports/enhanced_binder_parser.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-09-30 23:09 +0000

1"""Enhanced binder parser port interface. 

2 

3This module defines the port interface for enhanced binder parsing capabilities 

4that preserve extraneous text during binder operations. 

5""" 

6 

7from abc import ABC, abstractmethod 

8 

9from prosemark.domain.models import Binder 

10from prosemark.domain.parser_result import ParserResult 

11 

12 

13class EnhancedBinderParserPort(ABC): 

14 """Port interface for enhanced binder parsing with text preservation. 

15 

16 This port extends basic binder parsing capabilities to support preservation 

17 of extraneous text during parse and render operations, enabling full 

18 round-trip integrity for mixed structural and narrative content. 

19 """ 

20 

21 @abstractmethod 

22 def parse_with_preservation(self, markdown_content: str) -> ParserResult: 

23 """Parse markdown content preserving all non-structural text. 

24 

25 Args: 

26 markdown_content: Raw markdown text with mixed structural and narrative content 

27 

28 Returns: 

29 ParserResult containing binder structure and preserved text 

30 

31 Raises: 

32 BinderFormatError: If structural parsing fails 

33 

34 """ 

35 

36 @abstractmethod 

37 def render_with_preservation(self, parser_result: ParserResult) -> str: 

38 """Render ParserResult back to markdown preserving all text positioning. 

39 

40 Args: 

41 parser_result: Result from parse_with_preservation containing binder and preserved text 

42 

43 Returns: 

44 Markdown text with structural elements and preserved text 

45 

46 """ 

47 

48 @abstractmethod 

49 def parse_to_binder(self, markdown_content: str) -> Binder: 

50 """Parse markdown content into a Binder object (legacy method). 

51 

52 Args: 

53 markdown_content: Markdown text with unordered list structure 

54 

55 Returns: 

56 Binder object with parsed hierarchy 

57 

58 Raises: 

59 BinderFormatError: If markdown format is invalid or malformed 

60 

61 """ 

62 

63 @abstractmethod 

64 def render_from_binder(self, binder: Binder) -> str: 

65 """Render Binder object as markdown list content (legacy method). 

66 

67 Args: 

68 binder: Binder object to render 

69 

70 Returns: 

71 Markdown text with unordered list structure 

72 

73 """