Coverage for liitos/captions.py: 95.24%
41 statements
« prev ^ index » next coverage.py v7.6.8, created at 2024-11-25 15:36:16 +00:00
« prev ^ index » next coverage.py v7.6.8, created at 2024-11-25 15:36:16 +00:00
1from collections.abc import Iterable
2from typing import Union
4from liitos import log
7def weave(incoming: Iterable[str], lookup: Union[dict[str, str], None] = None) -> list[str]:
8 """Later alligator."""
9 outgoing = []
10 modus = 'copy'
11 table: list[str] = []
12 caption: list[str] = []
13 for slot, line in enumerate(incoming):
14 if modus == 'copy':
15 if line.startswith(r'\begin{longtable}'):
16 log.info(f'start of a table environment at line #{slot + 1}')
17 modus = 'table'
18 table = [line]
19 caption = []
20 else:
21 outgoing.append(line)
23 elif modus == 'table':
24 if line.startswith(r'\caption{'):
25 log.info(f'- found the caption start at line #{slot + 1}')
26 caption.append(line)
27 if not line.strip().endswith(r'}\tabularnewline'): 27 ↛ 13line 27 didn't jump to line 13 because the condition on line 27 was always true
28 log.info(f'- multi line caption at line #{slot + 1}')
29 modus = 'caption'
30 elif line.startswith(r'\end{longtable}'):
31 log.info(f'end of table env detected at line #{slot + 1}')
32 for stmt in table:
33 if not stmt.startswith(r'\endlastfoot'):
34 outgoing.append(stmt)
35 continue
36 else:
37 outgoing.extend(caption)
38 outgoing.append(stmt)
39 outgoing.append(line)
40 modus = 'copy'
41 else:
42 log.debug('- table continues')
43 table.append(line)
45 elif modus == 'caption': 45 ↛ 13line 45 didn't jump to line 13 because the condition on line 45 was always true
46 caption.append(line)
47 if line.strip().endswith(r'}\tabularnewline'): 47 ↛ 13line 47 didn't jump to line 13 because the condition on line 47 was always true
48 log.info(f'- caption read at line #{slot + 1}')
49 modus = 'table'
51 return outgoing