Skip to content

fix: slice search sections on the same line breaks markdown-it counts - #76

Open
Abhishek-B-R wants to merge 1 commit into
AlmanacCode:mainfrom
Abhishek-B-R:fix/section-line-breaks
Open

Abhishek-B-R wants to merge 1 commit into
AlmanacCode:mainfrom
Abhishek-B-R:fix/section-line-breaks

Conversation

@Abhishek-B-R

@Abhishek-B-R Abhishek-B-R commented Oct 1, 2026 •

Copy link
Copy Markdown

Summary

  • project_sections splits the body with a regex on \r\n, \r and \n instead of str.splitlines().
  • regression test in tests/test_wiki_sections.py.

Why

heading boundaries come from markdown-it's token.map, which only counts \n, \r\n and \r. splitlines() also breaks on form feeds, U+2028, U+2029, U+0085 and a few control chars, so one of those in a page shifts every section after it. the section body then starts with its own ## heading line and search reports the wrong heading for a match.

Verification

uv run pytest            # 565 passed
uv run ruff check .      # clean
git diff --check

Docs and wiki

  • README/docs updated if user-facing behavior changed.
  • .almanac/ wiki updated if an implementation decision, workflow, invariant, or gotcha changed.
  • Not applicable.

the new test fails on main and passes here.

Notes for reviewers

CRLF and lone \r bodies split the same as before. ruff format --check flags a trailing blank line in sections.py that is already on main; left it alone to keep the diff small.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

project_sections cut the body with str.splitlines(), but the heading
boundaries come from markdown-it token maps, which only count \n, \r\n
and \r as line breaks. splitlines() also breaks on form feeds, U+2028,
U+2029, U+0085 and a few control characters, so one of those in a page
shifted every later slice: section bodies picked up their own heading
line and the text before it moved into the wrong section.

Split on the same three breaks markdown-it uses.

This branch has not been deployed

No deployments
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