Repository navigation
Preserve words split by partial highlights in Markdown - #506
Open
Christiansada wants to merge 1 commit into
Open
Christiansada wants to merge 1 commit into
Christiansada wants to merge 1 commit into
Conversation
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.
Fixes #505.
A partial highlight makes MuPDF split a word into touching spans. Both Markdown paths appended a space between those spans, turning
<mark>Highlig</mark>htedinto<mark>Highlig</mark> hted.This uses shared separator logic for highlight transitions: retain real source whitespace, geometric gaps and original line/block boundaries; suppress the separator only for touching fragments (within 0.001 point). The layout serializer keeps its existing style-merging and hyphenation behaviour. The legacy serializer uses the same rule, including its plain header/code-line text. Other style transitions retain their existing spacing.
Tests generate the report’s PDF in memory, covering layout and legacy output, a following word, header output, whitespace, geometric gaps, source line/block boundaries, floating-point roundoff and unchanged same-style behaviour. No uploaded PDF or client material is added.
Validation:
mainhelpers at1200f2a; they pass with the patch.python -m pytest --noconftest tests/test_505.py tests/test_chunking_*.py tests/test_table_html.py tests/test_370.py tests/test_137.py -q: 108 passed, 3 skipped, with SWIG deprecation warnings.git diff --checkpassed.Local environment: Python 3.12.14, macOS arm64, released PyMuPDF/PyMuPDF4LLM 2.1 runtime. The repository’s tracked
srcwas overlaid into an isolated virtual environment; no system package was changed.--noconftestavoids the test bootstrap installing unrelated optional packages. I did not run the private Aptest build/CI, a full MuPDF source build, broad OCR testing or other platforms. The fix targets the reported horizontal highlight transition, not a general reconstruction of word boundaries from arbitrary PDF geometry.