Repository navigation
feat: let a walk see every block that holds one - #38
Merged
Merged
Conversation
Document::walk now yields each block with every block that holds it, outermost first, instead of its parent alone. The parent is the last of them, and the depth is how many there are. The walk already kept these blocks on its stack; it now hands each block a copy of them. A lint that needs to know where a block sits, such as how deeply a list is nested, no longer has to rebuild the tree from parents.
The density lint held a paragraph to max_item_chars only when a list item was its parent. A paragraph in a block quote inside a list item was held to max_paragraph_chars instead, though the lint's docs say a paragraph inside a list item counts as an item. It now looks at every block that holds the paragraph. In the corpus this changes the reports of three mixed/ fixtures. No fixture passes or fails that did not before.
9 tasks done
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
A refactor of the parsed tree representation.
Summary
Document::walkused to yield each block with its parent. It now yields each block with every block that holds it, outermost first. The parent is the last of them, and the depth is how many there are. The walk already kept those blocks on its stack and threw them away; now each block gets a copy.Of the three options in #29, this is the first: a
Vec<&Block>per block.walk()redundant, since its parent is justancestors.last().(&Block, &[&Block])cannot return early or use iterator adaptors.repo_layoutreturns from inside its walk, and the tests usefind,filterandmap.Vec, which does not allocate.The signature of
walk()changedThe item type went from
(&Block, Option<&Block>)to(&Block, Vec<&Block>).for (block, _) in document.walk()compiles unchanged.ancestors.last()instead ofparent.If the
banned_phraseslint (#32) uses the parent, whichever of the two PRs merges second needs that one-line change.Callers
densityuses the whole chain. See the bug below.treehelper intests/document.rsrebuilt each block's depth by searching for its parent by pointer. It is nowancestors.len().ancestors.last().max_emphasis,repo_layoutandbanned_charsignore the second element and are untouched.docs/design/deslag.asbuilt.mdnow describes the walk. To make room I cut detail from the same section (the metadata-block note, the examples of spans, "soft and hard", "never split"). The doc is 16,237 bytes, 10 fewer than onmain.Bug fixed: density and paragraphs nested in a list item
The density lint says a paragraph inside a list item is held to
max_item_chars, and documentsKind::Paragraphas "a paragraph outside any list item". The code only checked the paragraph's direct parent. So a paragraph in a block quote inside a list item was held tomax_paragraph_charsand reported as a paragraph. It now checks every block that holds it.This is the one intended change in output:
tests/cases/**/*.stderrfile changes.deslag checkwith[md.lints.density]over copies oftests/corpus/{human,llm,mixed}, before and after. The reports of threemixed/fixtures change. For example, a quoted abstract inside a list item indckc--awesome-ocap/README.mdis now reported as a list item.human/, 92llm/and 126mixed/.The regression test is
a_paragraph_in_a_quote_in_a_list_item_is_held_to_the_item_s_limitintests/density.rs. It is its own commit.Testing
make ci: exit 0a_walk_gives_every_block_that_holds_a_block_outermost_firstintests/document.rs: a list inside a block quote inside a list item, asserting the kinds of each block's chainmain'ssrc/and passes hereReferences