shufo / blade-formatter

An opinionated blade template formatter for Laravel that respects readability
https://www.npmjs.com/package/blade-formatter
MIT License
448 stars 25 forks source link

Mix of open/closed HTML tag and directives #646

Open shufo opened 2 years ago

shufo commented 2 years ago

Context (Environment)

Current Behavior

Currently the mix of open/closed HTML tag and directives result in unexpected format.

@if ($user)
  <div>
@else
  </div>
@endif

will format into

@if ($user)
    <div>
    @else
    </div>
@endif

Expected Behavior

It should be indent html tags based on blade directive

Input

@if ($user)
  <div>
@else
  </div>
@endif

Output

@if ($user)
  <div>
@else
  </div>
@endif

Detailed Description

It should set the indentation base to be inside of the directive, but not outside of the directive.

<div>
  @if ($user)
    <div>
  @else
    </div>
  @endif
</div>

Work around

Since the syntax preference between HTML and Blade is basically unresolvable, you should try to keep the HTML Open/Close tags as complete as possible within a single logical directive block

e.g.

<div>
  @if ($user)
    <div></div>
  @else
    <p></p>
  @endif
</div>
github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

francoism90 commented 1 year ago

@shufo Any update on this?

shufo commented 1 year ago

@francoism90 Sorry, still in progress due to the many edge cases.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

montchr commented 1 year ago

Still an issue afaik, should not have been closed by the bot.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] commented 10 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] commented 7 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] commented 5 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days