Skip to content

Preserve queries and fragments when rewriting Markdown file links - #746

Open
pabszero wants to merge 6 commits into
trentm:masterfrom
pabszero:fix-markdown-link-suffixes
Open

pabszero wants to merge 6 commits into
trentm:masterfrom
pabszero:fix-markdown-link-suffixes

Conversation

@pabszero

Copy link
Copy Markdown

With markdown-file-links, [guide](guide.md#install) keeps pointing to Markdown instead of HTML. Conversely, [part](guide.html#part.md) changes the fragment to #part.html. The same suffix check affects link definitions.

Split off query/fragment suffixes before checking the .md filename and share that conversion between inline links and definitions. Preserve the suffix exactly, including empty ?/# delimiters. Also let the extra run after definitions are stripped, so a document containing only a reference link is converted without needing another .md in the body.

Add three regression tests covering 34 inline/reference combinations, link_defs=False, and unchanged inline images. Update the README with the query/fragment behavior.

Validation on Windows, CPython 3.13.5:

  • The new tests against unchanged upstream e69bbdf produce 26 failing subtests/assertions.
  • With the fix, cd test && python test.py -- -knownfailure passes all 299 selected tests with all optional dependencies installed (including version-specific Pygments fixture selection).
  • python test/test_redos.py: all 10 cases pass.
  • git diff --check: clean. No PEP8 diagnostics on added Python lines; existing whole-file diagnostics remain (markdown2.py 412 to 410, test_markdown2.py unchanged at 68).

Other Python versions/platforms are left to CI. AI assistance: OpenAI Codex assisted with investigation, code, tests and this description. No human review or personal production usage is claimed.

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