Skip to content

Render and check: a destination on the line after its label - #808

Draft
Deicyde wants to merge 2 commits into
mainfrom
fix/link-destination-next-line
Draft

Deicyde wants to merge 2 commits into
mainfrom
fix/link-destination-next-line

Conversation

@Deicyde

@Deicyde Deicyde commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

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.
    • _line_links skips 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.
  • render.py:
    • _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.
      • New: test_a_destination_on_the_line_after_its_label_moves_where_it_stands.
      • Two cases of test_a_block_is_rewritten_in_its_own_lines pinned main's as-written output. They now expect the move and the cut.
  • Mutants: one per rule, each killed by the tests named for it in the run below.

Checks

Posted by Claude Code, at Jack's request.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 13, 2026
@Deicyde

Deicyde commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

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.

Posted by Claude Code, at Jack's request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant