fix(notion-writer): fence-aware image/translate, NtnUploadError boundary, dead-code removal
FIX 1: _content_has_local_images and extract_local_images now skip lines inside ``` fences so a local-image ref inside a code block is not treated as real. FIX 2: md_translate.translate() tracks fence state; callout/columns/mention transforms are suppressed for lines inside ``` ... ``` blocks (pass verbatim). FIX 3: main() catches NtnUploadError and prints a clean error + e.stderr before sys.exit(1); body moved to _main_body(parser, args). FIX 4: ntn_files.upload() raises NtnUploadError on empty stdout instead of IndexError, giving a clean message combined with FIX 3. FIX 5: Removed unused write_to_page() (both page paths are inlined). FIX 6: create_page_markdown() omits the 'markdown' key when value is falsy, avoiding empty-markdown sends on DB rows created without --file/--stdin. FIX 7: CLAUDE.md documents --allow-deleting-content scope (markdown engine only). TDD: Added test_fence_passthrough_no_transform (md_translate, suite now 8) and test_local_image_inside_fence_ignored (engine_routing, suite now 6). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -64,6 +64,18 @@ def test_content_has_local_images():
|
||||
assert notion_writer._content_has_local_images("no images") is False
|
||||
|
||||
|
||||
def test_local_image_inside_fence_ignored():
|
||||
"""A local image reference inside a fenced code block must NOT be detected
|
||||
as a real image by _content_has_local_images or extracted by extract_local_images."""
|
||||
fenced = "```markdown\n\n```"
|
||||
assert notion_writer._content_has_local_images(fenced) is False, \
|
||||
"_content_has_local_images should return False for image inside fence"
|
||||
without, imgs = notion_writer.extract_local_images(fenced)
|
||||
assert len(imgs) == 0, "extract_local_images should not extract image inside fence"
|
||||
# The fenced lines (including the image line) should be preserved verbatim
|
||||
assert "" in without, "fence content must be preserved in output"
|
||||
|
||||
|
||||
def run_all():
|
||||
tests = [
|
||||
test_create_page_markdown,
|
||||
@@ -71,6 +83,7 @@ def run_all():
|
||||
test_replace_markdown,
|
||||
test_extract_local_images_splits,
|
||||
test_content_has_local_images,
|
||||
test_local_image_inside_fence_ignored,
|
||||
]
|
||||
for t in tests:
|
||||
print(f"\n{t.__name__}")
|
||||
|
||||
Reference in New Issue
Block a user