(image_path: Path)
| 108 | """ |
| 109 | 验证并修复 CSV 内容(目标为 3 列:title, page_number, level)。 |
| 110 | 1. 若列数少于 3,尝试从右向左将全角逗号替换为半角逗号(最多替换两次)。 |
| 111 | 2. 若解析为 4 列以上,说明标题中包含了半角逗号,将前 n-2 列合并为 title。 |
| 112 | """ |
| 113 | lines = content.splitlines() |
| 114 | fixed_lines = [] |
| 115 | |
| 116 | for line in lines: |
| 117 | if not line.strip(): |
| 118 | continue |
| 119 | |
| 120 | # 尝试解析当前行 |
| 121 | try: |
| 122 | reader = csv.reader(StringIO(line)) |
| 123 | row = next(reader) |
| 124 | except Exception: |