Skip to content

fix: end every writer block with exactly one newline - #111

Merged
eitsupi merged 5 commits into
mainfrom
refactor/writer-block-terminator
Nov 14, 2026
Merged

eitsupi merged 5 commits into
mainfrom
refactor/writer-block-terminator

Conversation

@eitsupi

@eitsupi eitsupi commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

The list and definition list writers mixed up two kinds of newline: the one that ends a block, and the blank line between sibling blocks. Children that already ended their own lines got another newline on top, which left extra blank lines after lists, code blocks, and nested definition lists, and could make a tight list read as loose.

  • Structure checks for writer output (test: commits)
    • New test helpers parse writer output with pulldown-cmark (definition list extension enabled) and, when a pandoc binary is available, pandoc -f markdown, and render a normalized block tree: which blocks exist, how they nest, and whether lists are tight or loose.
    • String tests still pin the exact bytes; the trees catch output that looks plausible but parses differently. Set RD2QMD_REQUIRE_PANDOC to make a missing Pandoc a failure; the CI test job installs Pandoc 3.7.0.2 with r-lib/actions/setup-pandoc and sets it, so both oracles run on all three OSes.
    • The trees expose two existing defects, pinned as known bugs for follow-up: adjacent lists of the same kind merge into one loose list, and a description holding only a list turns its first item into an indented code block.
    • Boundaries between multiple definition list term groups are pinned with exact-output tests against the previous implementation first.
  • One newline per block (fix: commit)
    • Explicit writer helpers for the terminator that ends a block fragment and the separator between siblings. Every non-empty block fragment now ends with exactly one newline; containers insert separators only between siblings.
    • Raw HTML (verbatim) and empty tables or lists stay outside the contract; containers close the line after them.

Output changes

Removed blank lines only.

  • Snapshot diffs: 7 files, all blank-line removals, with identical Pandoc ASTs.
  • Converting the man pages of several real CRAN/GitHub packages with the old and new binaries, across the definition-list, list, and headings describe formats: 42 of 1179 files differ (20 for headings), all by removed blank lines with no added lines, and the Pandoc AST is identical under both the markdown and commonmark readers.
  • A tight list whose item holds a table or a definition list is no longer read as loose by pulldown-cmark, now matching Pandoc.
  • Inline nodes placed directly in a definition description (only reachable through AST input) are now written as separate blocks, as in list items.

String-equality tests pin the exact bytes but cannot tell whether those
bytes parse as intended. Add test helpers that parse writer output with
pulldown-cmark (with the definition list extension) and, when available,
Pandoc, and render a normalized block tree: which blocks exist, how they
nest, and whether lists are tight or loose.

Pin the current trees for root-level sequences, lists, and definition
lists. The trees expose two existing defects, pinned as known bugs:
adjacent lists of the same kind merge into one loose list, and a
description holding only a list turns its first item into an indented
code block.
List and definition list writers mixed up two kinds of newline: the one
that ends a block, and the blank line that separates two sibling blocks.
Items and term groups pushed unconditional newlines on top of children
that already ended their own lines, which left extra blank lines after
lists, code blocks, and nested definition lists, and could make a tight
list read as loose.

Introduce explicit helpers for the two: a terminator that ends a block
fragment, and a separator that writes the blank line between siblings.
Every non-empty block fragment now ends with exactly one newline, and
containers insert separators only between siblings. Raw HTML and empty
tables or lists stay outside the contract; containers close the line
after them.

Output changes are limited to removed blank lines. Converting the man
pages of several real packages with the old and new binaries changes 42
of 1179 files, all by removing blank lines, with identical Pandoc ASTs.
The pulldown-cmark tree dropped the text after an inline tag such as
emphasis or a link, so two items with different labels could compare
equal. Rows also joined their cells with " | ", which made one cell
containing "a | b" indistinguishable from two cells. Skip inline tags
before flushing block text, and render rows as cell arrays.

Also pin how inline nodes placed directly in a definition description
are written.
@eitsupi
eitsupi merged commit 880f53c into main Nov 14, 2026
14 checks passed
@eitsupi
eitsupi deleted the refactor/writer-block-terminator branch November 14, 2026 06:01
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