Repository navigation
feat: read each file once into a document - #26
Merged
Merged
Conversation
Add deslag::document, which reads a Markdown file once into layers that the lints share: - Blocks, nested as Markdown nests them. Code blocks, HTML blocks and frontmatter keep their raw text and hold no prose. - Pieces of text, spans such as emphasis and links, and points such as line breaks and the gaps between blocks. Each is a byte range in the file. - A flat row of tokens. Words come from the Unicode rules in the unicode-segmentation crate. Inline code, inline HTML, images and URLs are one token each. - Sentences over the tokens. banned_chars, density, max_emphasis and repo_layout now read the document instead of parsing Markdown on their own, and src/parse/markdown.rs is gone. max_size_bytes still reads raw bytes. No lint reads tokens or sentences yet. Two bugs go away with the old parsing, each with a regression test: - density skipped the text of a tight list item that opens with markup, such as "- **bold** rest". - max_emphasis counted the indentation of an indented HTML block as prose.
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.
Human Summary
Mostly a refactor, but also with couple of bugs found and fixed. Gives a parser and a document model.
Summary
The lints that are coming next judge sentences and words, not Markdown structure. Until now each lint parsed Markdown on its own and kept only what it needed. This PR adds
deslag::document, a public module that reads a file once into layers every lint can share:unicode-segmentation, a new dependency with no dependencies of its own. Inline code, inline HTML, images and bare URLs are one token each, never split into words.banned_chars,density,max_emphasisandrepo_layoutnow read the document instead of parsing Markdown themselves, andsrc/parse/markdown.rsis gone.max_size_bytesstill reads raw bytes. No lint reads tokens or sentences yet; they are the ground the list lint in #16 will stand on.Two TODO comments record known gaps. The sentence splitter ends a sentence after "Dr.". Prose inside a code block, HTML block or frontmatter is invisible to prose rules.
Two bugs fixed
The old parsing had two bugs that the document does not have. Each gets a regression test that fails on
main.densityskipped the text of a tight list item that opens with markup:- **bold** restcounted 5 characters, and- [a link](x)was not measured at all. On the corpus, 2,283 more list items are now measured, 82 files get a different report, and 12 more files fail at the default limits (8 LLM, 4 mixed, 0 human). No file that failed now passes.max_emphasiscounted the indentation of an indented HTML block as prose. This touches 8 corpus files. No span changes, and the largest move in a share is 0.09 points.banned_charsandrepo_layoutread exactly what they did before on all 1,257 corpus files.Testing
make ci: exit 0tests/casesstderr is byte-identical, and the corpus tests pass unchangedmainand on this branch, then comparedmain, where both failReferences