Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option closing-bracket-newline for html beautify #2316

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zhaojjiang
Copy link

This option is added to implement prettier's --bracket-same-line behavior.

Input code:

<div
  style="display: block;"
  width="100" height="200">
  aaaa
  <p>test content</p>
</div>

Output code:

<div
  style="display: block;"
  width="100"
  height="200"
>
  aaaa
  <p>test content</p>
</div>;

Description

  • Source branch in your fork has meaningful name (not main)

Before Merge Checklist

These items can be completed after PR is created.

(Check any items that are not applicable (NA) for this PR)

  • JavaScript implementation
  • Python implementation (NA if HTML beautifier)
  • Added Tests to data file(s)
  • Added command-line option(s) (NA if
  • README.md documents new feature/option(s)

This option allow you put closing bracket to seperate line
@bitwiseman
Copy link
Member

I'm not directly opposed to adding another config option for this setting, but this project has too many options already.

Similar to #1404 ... But for brace-style (which is currently not used in the html formatter except to be passed through to <script> contents).

@zhaojjiang
Copy link
Author

I understand your concerns a little bit.

I opened this pr because js-beautify is the basic dependency of vscode built-in html-language-feature extension which used to format html code.

There is no other way to let vscode add this option, the only way I found is open a pr in js-beautify and then wait for vscode update its dependency!

I think this project should not be so cautious aboud adding new features, as mentioned above, this project is now a built-in feature of vscode, many html format issues in vscode are linked to this project.

@bitwiseman
Copy link
Member

@zhaojjiang
The fact that this project is bundled in vscode means it needs to be even more cautious to not introduce breaking changes.

Do you want to take responsibility for potentially breaking millions of users?

// Add newline before tag closing bracket:
// 1. add newline only if 'force_expand_multiline' or 'closing-bracket-newline' is specified
// 2. add newline only if tag has wrapped_attrs
if ((this._is_wrap_attributes_force_expand_multiline || this._options.closing_bracket_newline) && last_tag_token.has_wrapped_attrs) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the behavior of this new option the same as force_expand_multiline ... If that is the case you don't need the new option. I think what you want is

Suggested change
if ((this._is_wrap_attributes_force_expand_multiline || this._options.closing_bracket_newline) && last_tag_token.has_wrapped_attrs) {
if ((this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) || this._options.closing_bracket_newline) {

But that might not be it either...

Copy link
Author

@zhaojjiang zhaojjiang Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the behavior of this new option the same as force_expand_multiline ... If that is the case you don't need the new option.

Yes, it is. This new option should work only with a tag which has wrapped attributes, it should not work when tag has no attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants