Skip to content

feat: embed any standalone http(s) URL as an external-article card (#262)#266

Open
katanumahotori wants to merge 1 commit into
drillan:mainfrom
katanumahotori:feat/external-article-fallback
Open

feat: embed any standalone http(s) URL as an external-article card (#262)#266
katanumahotori wants to merge 1 commit into
drillan:mainfrom
katanumahotori:feat/external-article-fallback

Conversation

@katanumahotori

Copy link
Copy Markdown

Closes #262

Problem

Standalone URLs outside the embed allowlist end up as plain unlinked text in the published article (<p>https://example.com</p>), while note.com's own editor turns any pasted URL into a link card.

Changes

  1. get_embed_service(): falls back to 'external-article' for any http(s) URL that matches no specific pattern. Specific patterns keep precedence; non-http(s) strings still return None. This reuses the exact mechanism already in place for Zenn / Qiita / connpass (/v2/embed_by_external_api with service=external-article).
  2. resolve_embed_keys(): when key registration fails, the figure is degraded to a visible <a> link paragraph instead of keeping an unregistered placeholder key (which note.com's frontend renders as nothing → silent content loss, see Issue feat: 埋め込みURL (YouTube, Twitter, note.com) のAPI化 #116).
  3. _convert_standalone_embed_urls(): unescape HTML entities before matching, so query strings containing & (e.g. Amazon affiliate URLs, escaped to &amp; by markdown-it) are neither mis-matched nor double-escaped.

Tests

  • Updated unit tests to the new semantics (generic http URLs are embeds; only non-http strings are unsupported).
  • New coverage: external-article fallback generation, link degradation on registration failure, & round-trip for query-string URLs.
  • uv run pytest tests/unit tests/integration: all pass (except 2 pre-existing test_auth_browser failures unrelated to this change).
  • ruff check / mypy: clean.

Verified E2E

Confirmed on a real note.com article (2026-06-10): 10 standalone URLs (personal site pages, an LP with query string, and 3 Amazon product URLs with affiliate parameters) were all registered via /v2/embed_by_external_api and render as proper link cards on the live page.

🤖 Generated with Claude Code

Standalone URLs that match no specific embed pattern previously stayed
as plain unlinked text in the published article. note.com's own editor
turns any pasted URL into a link card, so mirror that behavior:

- get_embed_service() falls back to 'external-article' for any other
  http(s) URL (specific patterns still take precedence). Non-http(s)
  strings keep returning None.
- resolve_embed_keys() now degrades a figure to a visible link
  paragraph when key registration fails, instead of leaving an
  unregistered placeholder key that note.com's frontend renders as
  nothing (silent content loss).
- _convert_standalone_embed_urls() unescapes HTML entities before
  matching, so query strings containing '&' (e.g. Amazon affiliate
  URLs) are not double-escaped.

Update unit tests for the new semantics and add coverage for the
fallback, the link degradation, and the '&' handling.
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.

Standalone URLs outside the embed allowlist end up as plain unlinked text

1 participant