Skip to content

Fix inline {% %} comments not preserving content after closing#114

Merged
dereuromark merged 1 commit intomasterfrom
fix/inline-brace-comments
Mar 23, 2026
Merged

Fix inline {% %} comments not preserving content after closing#114
dereuromark merged 1 commit intomasterfrom
fix/inline-brace-comments

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

Summary

The block parser was incorrectly treating {% comment %} text as a block-level comment, consuming the entire line and losing the text after %}.

Before fix:

  • {% comment %} text → (empty)
  • {% one %} text {% two %} → (empty)

After fix:

  • {% comment %} text<p> text</p>
  • {% one %} text {% two %}<p> text </p>

Root Cause

isCommentOpener() was returning true for any line starting with {%, even when the comment closed on the same line with content after it.

Fix

Updated isCommentOpener() to only treat a line as a block comment when:

  • The comment spans multiple lines (no closing %} on same line), OR
  • The comment is alone on the line (nothing meaningful after %})

Single-line comments with content after them are now handled as inline comments by the attribute parser, which correctly strips the comment while preserving surrounding text.

Tests

Added 5 tests covering:

  • Inline comment at start preserving text after
  • Multiple inline comments on same line
  • Inline comment in middle of text
  • {% %} inside code spans (should be preserved)
  • {% %} inside quoted attributes (should be preserved)

The block parser was incorrectly treating `{% comment %} text` as a
block-level comment, consuming the entire line and losing "text".

This fix updates `isCommentOpener()` to only treat a line as a block
comment when:
- The comment spans multiple lines (no closing %} on same line), OR
- The comment is alone on the line (nothing after %})

Single-line comments with content after them are now handled as inline
comments by the attribute parser, which correctly strips the comment
while preserving surrounding text.

Fixes:
- `{% comment %} text` now renders as `<p> text</p>`
- `{% one %} text {% two %}` now renders as `<p> text </p>`

Added 5 tests covering inline comment edge cases.
@dereuromark dereuromark added the bug Something isn't working label Mar 23, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.76%. Comparing base (bc80fc8) to head (3968252).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #114   +/-   ##
=========================================
  Coverage     93.75%   93.76%           
- Complexity     2340     2341    +1     
=========================================
  Files            79       79           
  Lines          6198     6205    +7     
=========================================
+ Hits           5811     5818    +7     
  Misses          387      387           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dereuromark dereuromark merged commit 844b948 into master Mar 23, 2026
6 checks passed
@dereuromark dereuromark deleted the fix/inline-brace-comments branch March 23, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant