Skip to content

fix(html): preserve whitespace around anchor text - #2396

Open
IZHAR ALI JAFFAR (Izharalijaffar) wants to merge 1 commit into
microsoft:mainfrom
Izharalijaffar:fix/html-anchor-whitespace
Open

fix(html): preserve whitespace around anchor text#2396
IZHAR ALI JAFFAR (Izharalijaffar) wants to merge 1 commit into
microsoft:mainfrom
Izharalijaffar:fix/html-anchor-whitespace

Conversation

@Izharalijaffar

Copy link
Copy Markdown

HTML anchor conversion trims text with chomp(), but several return paths discard the removed whitespace. For example, <p>before<a> middle </a>after</p> currently becomes beforemiddleafter, losing word boundaries.

Preserve the original text when an anchor has no destination, contains only whitespace, or appears inside <pre>. Include the extracted prefix and suffix when emitting an autolink. Normal links and rejected JavaScript links retain their existing behavior.

Adds regression coverage through MarkItDown.convert_stream() for missing/empty hrefs, named anchors, whitespace-only anchors, preformatted text, and autolinks, plus controls for normal and rejected links.

Validation on Windows, Python 3.12.14, markdownify 1.2.3:

  • Before the fix: 10 new regression cases failed; 8 cases passed.
  • After the fix: all 18 HTML tests pass.
  • Full core suite: 424 passed, 33 skipped, 3 failed. All three failures also reproduce with the original converter: test_file_uris and test_convert_case_insensitive_uri_schemes expect POSIX paths; test_doc_rlink attempts to write to C:\tmp\test_rlink.txt. Remote tests were skipped using the suite's GITHUB_ACTIONS setting; no live LLM calls were made.
  • pre-commit run --all-files: passed.
  • Wheel build: passed.
  • Focused mypy check reports the same five existing options attribute errors on both original and changed converter; no new errors.

Prepared and tested with Codex assistance.

@Izharalijaffar

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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