fix: parse_inline drops links at position 0 and marks() loses href#36
Open
ASRagab wants to merge 4 commits intoma2za:mainfrom
Open
fix: parse_inline drops links at position 0 and marks() loses href#36ASRagab wants to merge 4 commits intoma2za:mainfrom
ASRagab wants to merge 4 commits intoma2za:mainfrom
Conversation
added 2 commits
March 3, 2026 02:59
Two bugs in inline link handling:
1. parse_inline(): Links at the start of a line (position 0) were silently
dropped. The image-exclusion check `match.start() > 0 and ...` would
short-circuit to False when the link started at position 0, causing it
to be skipped entirely. Fixed by checking `match.start() == 0 or
text[match.start() - 1] != '!'` instead.
2. marks(): All link hrefs were set to null. parse_inline() returns marks
with the structure `{'type': 'link', 'attrs': {'href': url}}`, but
marks() only checked `mark.get('href')` at the top level. Added
fallback to `mark.get('attrs', {}).get('href')` to handle both
the attrs-nested format from parse_inline and the top-level format
used in the README examples.
Added tests covering both bugs plus regression tests for image exclusion.
Owner
|
hi, thank you for the contribution... can you remove all the formatting changes please? they make it hard to review |
Author
|
Done — I reverted the formatting-only changes so the diff is now just the two functional fixes (position-0 links + link href in marks) plus the new regression tests. Sorry about the noise earlier (there's still hidden whitespace it's removing). |
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.
Summary
Two bugs in inline link handling that cause all links created via
from_markdown()to have null hrefs, and links at the start of a line to be silently dropped.Bug 1: Links at position 0 are dropped
parse_inline()skips links that start at position 0 in the text. The image-exclusion check:Short-circuits to
Falsewhenmatch.start() == 0, causing the link to be skipped entirely.Fix: Check
match.start() == 0 or text[match.start() - 1] != "!"instead.Repro:
Bug 2: All link hrefs are null
parse_inline()returns marks with the structure{'type': 'link', 'attrs': {'href': url}}, butmarks()reads frommark.get('href')at the top level — missing the nested attrs entirely.Fix: Fall back to
mark.get('attrs', {}).get('href')when top-level href is not present. This preserves backward compatibility with the top-level format shown in the README examples.Repro:
Tests
Added
tests/substack/test_post.pywith 6 tests covering:All tests pass. Pre-commit hooks (black, isort, trailing-whitespace, end-of-file-fixer) all pass.