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

HTML formatter sends comments to a new line when the comment does not include a space as the first character #1823

Open
avigoldman opened this issue Jul 29, 2020 · 7 comments · May be fixed by #1915

Comments

@avigoldman
Copy link

avigoldman commented Jul 29, 2020

Description

The HTML formatter sends comments to a new line when the comment does not include a space as the first character. It works properly when the HTML comment starts with any white space character. I believe the issue is here: https://github.com/beautify-web/js-beautify/blob/master/js/src/html/beautifier.js#L698

Related issues: #1337 #426

Input

The code looked like this before beautification:

<!--start button--><button>Click here</button><!--end button-->

Expected Output

The code should have looked like this after beautification:

<!--start button--><button>Click here</button><!--end button-->

Actual Output

The code actually looked like this after beautification:

<!--start button--><button>Click here</button>
<!--end button-->

To have this function properly add a space at the start of the second comment.

Input

The code looked like this before beautification:

<!--start button--><button>Click here</button><!-- end button-->

Actual Output

The code actually looked like this after beautification:

<!--start button--><button>Click here</button><!-- end button-->

Environment

I tested this on beautifier.io

Settings

{
  "indent_size": "2",
  "indent_char": " ",
  "max_preserve_newlines": "-1",
  "preserve_newlines": false,
  "keep_array_indentation": false,
  "break_chained_methods": false,
  "indent_scripts": "normal",
  "brace_style": "collapse",
  "space_before_conditional": false,
  "unescape_strings": false,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "0",
  "indent_inner_html": true,
  "comma_first": false,
  "e4x": false,
  "indent_empty_lines": false
}
@bitwiseman
Copy link
Member

This looks similar to #1301, but it is not the same.

@bitwiseman
Copy link
Member

This problem is even more apparent if for something like:

<span><!--start button--><button>Click here</button><!--end button--></span>

Which turns into:

<span>
    <!--start button--><button>Click here</button>
    <!--end button-->
</span>

This adds space between <span> and <button> and space inside the <button>. 😭

@bitwiseman bitwiseman modified the milestones: v1.11.x, v1.12.x Aug 11, 2020
@bitwiseman bitwiseman modified the milestones: v1.12.x, 1.13.x Aug 20, 2020
@cfya
Copy link

cfya commented Aug 24, 2020

I would like to work on this @avigoldman @aashigupta19

@bitwiseman
Copy link
Member

@cfya
Please do!

@bitwiseman bitwiseman modified the milestones: v1.13.1, v1.13.x Jan 8, 2021
@bitwiseman bitwiseman modified the milestones: v1.13.6, v1.13.x Jan 26, 2021
@carolinekistler
Copy link

Hi! I have a project for a software methodology class to contribute to an open source repo and I am very interested in working on this project. Could I be assigned to this issue? Thanks!

@bitwiseman
Copy link
Member

@carolinekistler There you go, if you have any questions please join the project gitter.im room .

@bitwiseman bitwiseman modified the milestones: v1.13.7, v1.13.x Apr 13, 2021
@bitwiseman
Copy link
Member

To clarify, I think the requested behavior is that the following input remains unchanged:

<button>Click here</button><!--end button-->
<button>Click here</button><!-- end button-->
<button>Click here</button>
<!--end button-->
<button>Click here</button>
<!-- end button-->

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