Skip to content

fix(html): keep blank lines between blocks in indented HTML - #16

Merged
chaliy merged 1 commit into
mainfrom
claude/project-thread-s7y4cp
Oct 26, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/project-thread-s7y4cp

Conversation

@chaliy

@chaliy chaliy commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

What changed

HTML whose blocks are separated by source indentation (almost every real web page) now renders with blank lines between blocks and no leading spaces. Before, everything after the first block ran together with a leading space, which also stopped later headings and tables from being markdown at all.

The parser now normalizes block-context node lists (document body, blockquote, list item): whitespace-only inline runs between blocks are dropped, and loose inline text next to blocks becomes its own paragraph. Pure-inline content is untouched, so spaces between inline siblings survive.

Why

Found during the maintenance smoke test of examples/basic.rs. The golden fixtures had recorded the broken output, so tests passed.

Before / After

$ printf '<body>\n  <h1>A</h1>\n  <p>B</p>\n</body>' | markkit extract -
# before
# A
 B
# after
# A

B

examples/basic.rs now prints separated heading, paragraph, list and link paragraph. All 9 golden fixtures regenerated; each diff only adds blank lines and removes the leading space (reviewed one by one).

Tests: 7 new integration tests (indented blocks, nested transparent containers, blockquote paragraphs, adjacent lists, loose text, inline-only unchanged) and a property test asserting indented and compact documents render identically. The property test fails on the old parser.

Known limitation, documented rather than fixed here: after an unclosed <strong>, html5ever wraps the following paragraphs in it, so they render inside ** (see malformed fixture).

Risk

  • Low / Medium
  • Output changes for any multi-block HTML (intended). Consumers comparing exact output will see the added blank lines.

Checklist

  • Tests added or updated
  • Backward compatibility considered (output change is the fix; CHANGELOG Fixed entry)

Generated by Claude Code

Whitespace-only text between block elements stayed in block-context node
lists as Text(" "), so the renderer saw no adjacent blocks: headings,
paragraphs, lists and tables after the first ran together with a leading
space ("# A\n B"), breaking headings and tables as markdown. Normalize
block-context lists (body, blockquote, list item): drop whitespace-only
inline runs, wrap loose inline runs next to blocks in a Paragraph.

Golden fixtures had recorded the broken output and are regenerated.
Adds integration tests and a property test that indentation never
changes output.
@chaliy chaliy self-assigned this Oct 26, 2026
@chaliy
chaliy merged commit 6f873c1 into main Oct 26, 2026
10 checks passed
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