You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Render and check: a destination on the line after its label - #808
Render now moves or leaves out a reference definition's target, or an inline link's or image's destination, that starts on the line after its label, as it already does one on the label's line, with the same warning. Check and autoform move read such a definition, so a reference link through it counts and moves with its target.
Premise
User: a project whose articles break a link or a reference definition after its label, as editors that wrap at a column do, and the agents that run check and autoform move on it.
Problem: the site's Markdown reads [n]: with the target on the next line as a definition (Python-Markdown's ReferenceProcessor.RE allows a line break before the target), and [text]( with the destination on the next line as a link. On main, render reads a definition on one line only, and its image and link loops skip a destination on a later line ("published as written"). So a page can link a hidden file or one outside the blueprint, and a strict build fails on it, with no warning from render or check. This was the should-fix in the Render and check: reference links to left-out files, unpublished pages, and case variants #787 review: on main, 6 next-line cases failed and 2 controls passed (https://github.com/facebookresearch/autoform-bot/actions/runs/43356526481). Check's link_definitions also read one line, so a reference link through such a definition was not a dependency link, and autoform move named it uncounted instead of moving it.
Replaces: the one-line reading of a definition in render and check, and render's skip of a destination on a later line.
Deletes: the two "published as written" skips in render's image and link loops. Nothing else can go: a definition on one line reads as before.
What changes
markdown.py:
link_definitions reads a label alone on its line, with its target on the next, through _definition_at. That is the former body of _definition_span, which now returns the match.
_later_target finds a definition whose label stands alone, after any quote or list markers, with its target starting on the next line.
_rewrite_links moves that target where it stands. A definition that goes leaves each line its quote markers, so a quote still holds the lines after it.
_page_definitions reads such a definition, so a reference link through it is rewritten, or cut to its text.
The image and link loops match on a mask with each line's quote markers blanked (_link_mask(..., quoted=True)). A moved inline link keeps the break and quote markers before its destination, so every later line stays where it was written.
Scope: check reads such a definition wherever it reads a one-line definition, which is outside a quote or list item; it reads neither layout inside one. In a quote or list item, render still moves or leaves out the target, and warns.
Tests:
tests/test_markdown.py:
New: test_a_definition_whose_target_is_on_the_next_line_is_read. Two layouts are read; a blank line and a setext underline are not. Each case is checked against the site's HTML.
test_retarget_links_names_a_definition_whose_destination_is_on_the_next_line becomes ..._retargets_...: the link moves and nothing is uncounted.
test_retarget_links_leaves_what_no_reader_counts_and_names_it drops its next-line definition, which a reader now counts.
tests/ui/test_render.py:
New: test_a_destination_on_the_line_after_its_label_is_left_out_too, with five cases: definitions, titled, inline, quoted and listed. Each checks the kept text, that no .private remains, and the same warning from render and from publication_issues, which check reports.
No blockers. The six next-line cases from the #787 review's scratch run (https://github.com/facebookresearch/autoform-bot/actions/runs/43356526481) pass at deb89d2, by direct calls with that run's test: render leaves out the hidden, outside and atlas.json targets, the image's, and both inline destinations. Check reads the layouts the site reads (a label inside a block, a target indented past four spaces, a title on the target's line or the next, two such definitions in a row), and still reads none after a blank line or a setext underline. One should-fix, from the reader-agreement test: tests/test_markdown_agreement.py still leaves out a definition "over two lines, which link_definitions does not read" (line 71), which this makes untrue outside quotes and lists, so its grammar could now write some definitions over two lines and cover this reading; they agree at this head. Smaller: its "line read" class still allows one top-level case of the layout, [d]: then [a1z](l1.md), where link_definitions now reads the second line as d's target, as the site does, but markdown_links still reads a link there; skipping that line in the line reading, as the label is skipped, would leave the class's definition-target clause to quotes and list items.
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
CLA SignedThis label is managed by the Meta Open Source bot.
1 participant
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.
Render now moves or leaves out a reference definition's target, or an inline link's or image's destination, that starts on the line after its label, as it already does one on the label's line, with the same warning. Check and
autoform moveread such a definition, so a reference link through it counts and moves with its target.Premise
checkandautoform moveon it.[n]:with the target on the next line as a definition (Python-Markdown'sReferenceProcessor.REallows a line break before the target), and[text](with the destination on the next line as a link. On main, render reads a definition on one line only, and its image and link loops skip a destination on a later line ("published as written"). So a page can link a hidden file or one outside the blueprint, and a strict build fails on it, with no warning from render or check. This was the should-fix in the Render and check: reference links to left-out files, unpublished pages, and case variants #787 review: on main, 6 next-line cases failed and 2 controls passed (https://github.com/facebookresearch/autoform-bot/actions/runs/43356526481). Check'slink_definitionsalso read one line, so a reference link through such a definition was not a dependency link, andautoform movenamed it uncounted instead of moving it.What changes
link_definitionsreads a label alone on its line, with its target on the next, through_definition_at. That is the former body of_definition_span, which now returns the match._line_linksskips such a label, so the line-at-a-time reading (Let work and search omit what they can't represent, and have check warn #325) doesn't count[n]:as a shortcut reference link once the definition is read._later_targetfinds a definition whose label stands alone, after any quote or list markers, with its target starting on the next line._rewrite_linksmoves that target where it stands. A definition that goes leaves each line its quote markers, so a quote still holds the lines after it._page_definitionsreads such a definition, so a reference link through it is rewritten, or cut to its text._link_mask(..., quoted=True)). A moved inline link keeps the break and quote markers before its destination, so every later line stays where it was written.tests/test_markdown.py:test_a_definition_whose_target_is_on_the_next_line_is_read. Two layouts are read; a blank line and a setext underline are not. Each case is checked against the site's HTML.test_retarget_links_names_a_definition_whose_destination_is_on_the_next_linebecomes..._retargets_...: the link moves and nothing is uncounted.test_retarget_links_leaves_what_no_reader_counts_and_names_itdrops its next-line definition, which a reader now counts.tests/ui/test_render.py:test_a_destination_on_the_line_after_its_label_is_left_out_too, with five cases: definitions, titled, inline, quoted and listed. Each checks the kept text, that no.privateremains, and the same warning from render and frompublication_issues, which check reports.test_a_destination_on_the_line_after_its_label_moves_where_it_stands.test_a_block_is_rewritten_in_its_own_linespinned main's as-written output. They now expect the move and the cut.check-reads-no-next-line-definition:link_definitionsignores a label alone.line-reads-a-next-line-label:_line_linkscounts the label as a link.render-keeps-a-next-line-definition:_rewrite_linkswithout_later_target.render-moves-no-next-line-target: the target is kept as written.page-reads-no-next-line-definition:_page_definitionswithout_later_target.image-skips-a-next-line-destinationandlink-skips-a-next-line-destination: main's skips put back.quote-markers-not-blanked: the link loop matches on main's mask.moved-link-loses-its-lead: a moved link drops the break before its destination.tests/test_markdown_agreement.pyfrom Tests: compare the links and code spans markdown.py reads with the site's #807, gave 1744 passed and 1 skipped. That run was on Render and check: reference links to left-out files, unpublished pages, and case variants #787's head; this branch is the same commit replayed onto main, with the new test moved in front of the one Tests: compare the links and code spans markdown.py reads with the site's #807 kept.Checks
ruff checkwith the locked ruff 0.15.17 passes on the changed files, and this PR's CI runs the suite.git merge-treewith it conflicts only in CHANGELOG.md.Posted by Claude Code, at Jack's request.