Coverage for src/wiktextract/extractor/zh/note.py: 96%

27 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-15 05:18 +0000

1from wikitextprocessor import NodeKind, WikiNode 

2 

3from wiktextract.page import clean_node 

4from wiktextract.wxr_context import WiktextractContext 

5 

6from .models import WordEntry 

7 

8 

9def extract_note_section( 

10 wxr: WiktextractContext, word_entry: WordEntry, level_node: WikiNode 

11) -> None: 

12 has_list = False 

13 for index, list_node in level_node.find_child(NodeKind.LIST, True): 

14 if not has_list: 14 ↛ 19line 14 didn't jump to line 19 because the condition on line 14 was always true

15 has_list = True 

16 note = clean_node(wxr, word_entry, level_node.children[:index]) 

17 if note != "": 

18 word_entry.notes.append(note) 

19 for list_item in list_node.find_child(NodeKind.LIST_ITEM): 

20 note = extract_node_list_item(wxr, list_item) 

21 if note != "": 21 ↛ 19line 21 didn't jump to line 19 because the condition on line 21 was always true

22 word_entry.notes.append(note) 

23 

24 if not has_list: 

25 word_entry.notes.append( 

26 clean_node(wxr, word_entry, level_node.children) 

27 ) 

28 

29 

30def extract_node_list_item(wxr: WiktextractContext, list_item: WikiNode) -> str: 

31 nodes = [] 

32 child_str_list = [] 

33 for node in list_item.children: 

34 if isinstance(node, WikiNode) and node.kind == NodeKind.LIST: 

35 for child_list_item in node.find_child(NodeKind.LIST_ITEM): 

36 child_str_list.append( 

37 extract_node_list_item(wxr, child_list_item) 

38 ) 

39 else: 

40 nodes.append(node) 

41 return clean_node(wxr, None, nodes) + " ".join(child_str_list)