Coverage for fpdf2_textindex/interface/reference.py: 100.00%

28 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-01 14:22 +0000

1"""Reference.""" 

2 

3from __future__ import annotations 

4 

5import dataclasses 

6 

7from fpdf2_textindex import constants as const 

8from fpdf2_textindex.interface.link_location import LinkLocation 

9 

10 

11@dataclasses.dataclass(kw_only=True, slots=True) 

12class Reference: 

13 """Reference.""" 

14 

15 start_id: int 

16 """The start id of the reference.""" 

17 

18 start_suffix: str | None = None 

19 """The start suffix of the reference or `None`.""" 

20 

21 start_location: LinkLocation | None = dataclasses.field( 

22 default=None, init=False 

23 ) 

24 """The start (link) location in the document the reference is set at.""" 

25 

26 end_id: int | None = dataclasses.field(default=None, init=False) 

27 """The end id of the reference or `None`.""" 

28 

29 end_suffix: str | None = dataclasses.field(default=None, init=False) 

30 """The end suffix of the reference or `None`.""" 

31 

32 end_location: LinkLocation | None = dataclasses.field( 

33 default=None, init=False 

34 ) 

35 """The end (link) location in the document the reference is set at.""" 

36 

37 locator_emphasis: bool = False 

38 """Whether to emphasize the locator (page number) of the reference in the 

39 text index (`True`) or not (`False`).""" 

40 

41 @property 

42 def start_link(self) -> str: 

43 """The start link in the document that must be set in the text index to 

44 lead from the text to the text index. 

45 """ 

46 return f"{const.INDEX_ID_PREFIX:s}{self.start_id:d}" 

47 

48 @property 

49 def end_link(self) -> str | None: 

50 """The end link in the document that must be set in the text index to 

51 lead from the text to the text index. In case of no end id, the end link 

52 will be `None`. 

53 """ 

54 if self.end_id is None: 

55 return None 

56 return f"{const.INDEX_ID_PREFIX:s}{self.end_id:d}"