From 9b244f56cd9be22d151ef2d4fdee570843751631 Mon Sep 17 00:00:00 2001 From: Research Assistant Date: Mon, 1 Jun 2026 11:48:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20correct=20ocr=5Fredo=20property=20insert?= =?UTF-8?q?ion=20=E2=80=94=20find=20block=20end,=20avoid=20broken=20YAML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paperforge/worker/base_views.py | 21 ++++++++++++++++----- tests/test_base_views.py | 6 +++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/paperforge/worker/base_views.py b/paperforge/worker/base_views.py index e54f4e20..228a633c 100644 --- a/paperforge/worker/base_views.py +++ b/paperforge/worker/base_views.py @@ -477,11 +477,22 @@ def ensure_base_views(vault: Path, paths: dict[str, Path], config: dict, force: updated += "\n" + _render_single_pf_view(v) # Check for missing properties (e.g. ocr_redo) - if " ocr_redo:" not in updated and "properties:" in updated: - updated = updated.replace( - " ocr_status:\n displayName: \"OCR Status\"", - " ocr_status:\n displayName: \"OCR Status\"\n ocr_redo:\n displayName: \"重做OCR\"" - ) + if " ocr_redo:" not in updated: + lines = updated.split("\n") + prop_insert_idx = None + for i, line in enumerate(lines): + stripped = line.strip() + if stripped.startswith("ocr_status:") and not stripped.startswith("ocr_status "): + # Find the end of the ocr_status block (next line without leading space or next property) + blk_end = i + 1 + while blk_end < len(lines) and lines[blk_end].startswith(" ") and not lines[blk_end].lstrip().startswith("ocr_"): + blk_end += 1 + prop_insert_idx = blk_end + break + if prop_insert_idx is not None: + lines.insert(prop_insert_idx, " ocr_redo:") + lines.insert(prop_insert_idx + 1, ' displayName: "重做OCR"') + updated = "\n".join(lines) if updated != existing: base_path.write_text(updated, encoding="utf-8") diff --git a/tests/test_base_views.py b/tests/test_base_views.py index ffae1818..7e0e8dc3 100644 --- a/tests/test_base_views.py +++ b/tests/test_base_views.py @@ -262,7 +262,11 @@ views: - file.inFolder("Resources/Literature/骨科") - file.ext == "md" - !zotero_key.isEmpty() -properties: {} +properties: + ocr_status: + displayName: "OCR Status" + deep_reading_status: + displayName: "Deep Reading" views: # PAPERFORGE_VIEW: 控制面板 - type: table