Skip to content

fix: drop all leading whitespace before the first attribute - #327

Closed
DahanItamar wants to merge 1 commit into
taoqf:mainfrom
DahanItamar:fix/first-attribute-whitespace
Closed

DahanItamar wants to merge 1 commit into
taoqf:mainfrom
DahanItamar:fix/first-attribute-whitespace

Conversation

@DahanItamar

Copy link
Copy Markdown

Fixes #300.

The markup pattern captures the attributes together with the whitespace that follows the tag name, but the parser removed only its first character (attributes.slice(1)). When the first attribute sits on its own line, the remaining indentation was kept in rawAttrs, and toString() then added its own separating space:

parse('<button\n   data-primary>Go</button>').toString();
// before: '<button    data-primary>Go</button>'
// after:  '<button data-primary>Go</button>'

This strips all leading whitespace instead. Whitespace between attributes is kept as before, and markup that already had a single space before the first attribute serializes unchanged.

Validation:

  • Build passed (tsdown).
  • Full suite passed on Node 24: 309 passing, 13 existing pending.
  • The new test/tests/issues/300.js covers rawAttrs, newline, tab and multi-space separators, and the unchanged single-space case. Three of its four cases failed before the fix.
  • git diff --check passed. ESLint still can't initialize with the locked TypeScript installation, same as noted in fix: preserve table rows with omitted end tags #322.

🤖 Generated with Claude Code

The attribute capture includes the whitespace after the tag name, but
only its first character was removed. When the first attribute was on
a new line, the remaining indentation stayed in rawAttrs, and
toString() added another space in front of it.

Fixes #300.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DahanItamar DahanItamar closed this by deleting the head repository Oct 28, 2026
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.

toString() results in wrong formatting for first attribute

1 participant