Skip to content

Conversation

@luandro
Copy link
Contributor

@luandro luandro commented Nov 27, 2025

Images that are hyperlinked in Notion were losing their links during the markdown conversion process. This fix adds:

  1. Custom image transformer in notionClient.ts that detects hyperlinks on Notion image blocks (from caption rich_text or link property) and wraps images in markdown link syntax: alt

  2. Enhanced image extraction regex in imageReplacer.ts to handle both:

    • Regular images: alt
    • Hyperlinked images: alt
  3. Updated image replacement logic to preserve hyperlink wrappers when replacing Notion image URLs with local paths

  4. Comprehensive tests for hyperlinked image handling

Fixes #96

Images that are hyperlinked in Notion were losing their links during
the markdown conversion process. This fix adds:

1. Custom image transformer in notionClient.ts that detects hyperlinks
   on Notion image blocks (from caption rich_text or link property) and
   wraps images in markdown link syntax: [![alt](img-url)](link-url)

2. Enhanced image extraction regex in imageReplacer.ts to handle both:
   - Regular images: ![alt](url)
   - Hyperlinked images: [![alt](img-url)](link-url)

3. Updated image replacement logic to preserve hyperlink wrappers when
   replacing Notion image URLs with local paths

4. Comprehensive tests for hyperlinked image handling

Fixes #96
@digidem digidem deleted a comment from chatgpt-codex-connector bot Nov 27, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 27, 2025

🚀 Preview Deployment

Your documentation preview is ready!

Preview URL: https://pr-98.comapeo-docs.pages.dev

🔄 Content: Regenerated 5 pages from Notion (script changes detected)

💡 Tip: Add label fetch-all-pages to test with full content, or fetch-10-pages for broader coverage.

This preview will update automatically when you push new commits to this PR.


Built with commit a0941d3

Based on research into Notion's linking behavior, hyperlinks on images
are stored in the caption as link annotations. Updated the image
transformer to:

1. Check caption rich_text items for link annotations first
2. Extract the link URL from the first linked caption item
3. Use non-linked caption text as alt text
4. Add fallback checks for image.link and block-level link properties
5. Add debug logging to help diagnose hyperlink detection issues

This should correctly detect and preserve image hyperlinks from Notion.

Related to #96
Since Notion's "Add link" menu option doesn't expose hyperlinks via the
API, implement a workaround that detects URLs in image captions:

Method 1: Link annotations in caption rich_text
- Detects when URLs are formatted as links in captions
- Uses the link.url property from the rich_text annotation

Method 2: Plain text URL detection (NEW)
- Detects URLs typed as plain text in captions
- Uses regex to extract http(s) URLs: /https?:\/\/[^\s]+/
- Separates URL from alt text

Method 3 & 4: Future-proofing
- Checks for image.link and block.link properties
- Will work if Notion adds API support in the future

Users can now make images clickable by:
1. Typing a URL in the image caption (preferred workaround)
2. Pasting a link in the caption (Notion converts it automatically)

Note: The Notion UI "Add link" feature is not supported by the API.
Images using that feature will not have clickable links in the output.

Related to #96
- Wrap console.log in IS_TEST_ENV check for cleaner test output
- Use consistent ✓ prefix for success messages
- Shorten log message for brevity
@luandro luandro merged commit 7a63eb4 into main Nov 27, 2025
4 checks passed
@luandro luandro deleted the claude/fix-hyperlinked-images-01Mo1TjQHC8zwZDNhEkZeTGY branch November 27, 2025 20:17
@github-actions
Copy link
Contributor

🧹 Preview Deployment Cleanup

The preview deployment for this PR has been cleaned up.

Preview URL was: https://pr-98.comapeo-docs.pages.dev


Note: Cloudflare Pages deployments follow automatic retention policies. Old previews are cleaned up automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hyperlinked images don't work

3 participants