Skip to content

Fix internallinks crash on textless targets; match renderer header ids - #213

Merged
johndgiese merged 1 commit into
mainfrom
fix-internallinks-nontext-target
Jul 28, 2026
Merged

Fix internallinks crash on textless targets; match renderer header ids#213
johndgiese merged 1 commit into
mainfrom
fix-internallinks-nontext-target

Conversation

@johndgiese

Copy link
Copy Markdown
Contributor

Found while enabling n2y.plugins.internallinks on innolitics.github.io to fix 52 broken same-page links in production articles:

  1. Crash on textless targets. Links can point at blocks with no rich_text (images, dividers). The plugin raised AttributeError: 'NewImageBlock' object has no attribute 'rich_text', failing the entire page export. Now logs a warning and leaves the link unresolved. Regression test added (link to a divider block).

  2. Anchors didn't match renderer ids for headings with trailing spaces. Notion heading text can have trailing whitespace, producing anchors like #actual-use-testing- while both pandoc and kramdown generate #actual-use-testing (they strip heading whitespace before id generation). header_id_from_text now strips first — this also fixes the same latent issue in linkedheaders and heading-block ids.

Verified against a real affected article (2016 Human Factors guidance): 24+ links resolve to correct anchors, 5 image-target links remain unresolved-but-harmless, no crash. Local pytest (offline subset): same results as main except the new test passing; the 5 test_blocks failures on my machine reproduce on unmodified main and are pandoc 3.9-vs-2.19 artifacts.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EwuTg4uAA3UCEeiNLqtpdC

Two fixes for the internallinks plugin surfaced by enabling it on
innolitics.github.io:

- Links can target blocks with no rich_text (images, dividers); the
  plugin crashed with AttributeError and killed the whole page export.
  Leave such links unresolved with a warning instead.
- Notion heading text can carry trailing spaces, which became trailing
  hyphens in generated anchors (#actual-use-testing-) that don't match
  the ids markdown renderers produce (pandoc and kramdown both strip
  surrounding whitespace before id generation). Strip in
  header_id_from_text, which also fixes linkedheaders and heading ids.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EwuTg4uAA3UCEeiNLqtpdC
@johndgiese
johndgiese merged commit b970a0d into main Jul 28, 2026
4 checks passed
@johndgiese
johndgiese deleted the fix-internallinks-nontext-target branch July 28, 2026 04:06
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.

1 participant