(text: str)
| 43 | |
| 44 | |
| 45 | def parse_table(text: str) -> list[dict]: |
| 46 | body = text.split("---", 2)[-1].strip() |
| 47 | lines = body.split("\n") |
| 48 | |
| 49 | table_started = False |
| 50 | raw_rows: list[str] = [] |
| 51 | pending_overflow = "" |
| 52 | |
| 53 | for line in lines: |
| 54 | stripped = line.strip() |
| 55 | if not stripped: |
| 56 | if pending_overflow: |
| 57 | raw_rows.append(pending_overflow) |
| 58 | pending_overflow = "" |
| 59 | continue |
| 60 | |
| 61 | if stripped.startswith("分类编码"): |
| 62 | table_started = True |
| 63 | continue |
| 64 | if not table_started: |
| 65 | continue |
| 66 | |
| 67 | if stripped.startswith("---") and "|" in stripped: |
| 68 | continue |
| 69 | |
| 70 | if "|" in stripped: |
| 71 | if pending_overflow: |
| 72 | raw_rows.append(pending_overflow) |
| 73 | pending_overflow = "" |
| 74 | raw_rows.append(stripped) |
| 75 | else: |
| 76 | if raw_rows: |
| 77 | raw_rows[-1] += "\n" + stripped |
| 78 | |
| 79 | if pending_overflow: |
| 80 | raw_rows.append(pending_overflow) |
| 81 | |
| 82 | entries = [] |
| 83 | for row in raw_rows: |
| 84 | cols = [c.strip().strip("*").strip() for c in row.split("|")] |
| 85 | while len(cols) < 5: |
| 86 | cols.append("") |
| 87 | |
| 88 | raw_code = cols[0] |
| 89 | product_name = cols[1] |
| 90 | product_desc = cols[2] |
| 91 | device_class = normalize_class(cols[3]) |
| 92 | remarks = cols[4] if len(cols) > 4 else "" |
| 93 | |
| 94 | raw_code_clean = re.sub(r"\s+", " ", raw_code).strip() |
| 95 | codes_found = re.findall(r"\d{2}-\d{2}-\d{2}", raw_code_clean) |
| 96 | |
| 97 | if CODE_L1_RE.match(raw_code_clean): |
| 98 | scope = "l1" |
| 99 | code = raw_code_clean |
| 100 | elif CODE_L3_RE.match(raw_code_clean): |
| 101 | scope = "l3" |
| 102 | code = raw_code_clean |
no test coverage detected