Fix internallinks crash on textless targets; match renderer header ids - #213
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while enabling
n2y.plugins.internallinkson innolitics.github.io to fix 52 broken same-page links in production articles:Crash on textless targets. Links can point at blocks with no
rich_text(images, dividers). The plugin raisedAttributeError: '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).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_textnow strips first — this also fixes the same latent issue inlinkedheadersand 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_blocksfailures 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