js-beautify icon indicating copy to clipboard operation
js-beautify copied to clipboard

HTML <!-- comments --> placed within text alters whitespace

Open MCTaylor17 opened this issue 7 years ago • 7 comments

Description

When HTML comments are beautified, it removes the whitespace surrounding the comment. This is problematic if the HTML comments occur within text blocks such as paragraphs.

Input

When a comment exists inside a text block:

<div><p>Hello <!-- Comment -->World</p></div>

Expected

Ideally, I would like comments to always be ignored wherever they occur, like so:

<div>
	<p>Hello <!-- Comment -->World</p>
</div>

Actual

The problem with the above is the removal of the space following Hello like so:

<div>
	<p>Hello
		<!-- Comment -->World</p>
</div>

Settings

Example:

{
	"indent_size": 1,
	"indent_char": "	",
	"wrap_line_length": 0,
	"preserve_newlines": true,
	"max_preserve_newlines": 3
}

Note

I'm aware that I could use:

{
	"content_unformatted": ["p","li","td", "...", "..."]
}

But this doesn't strike me as an ideal solution. I think it would be better if there was an option to ignore comment tags specifically.

MCTaylor17 avatar Dec 11 '17 19:12 MCTaylor17

I'm having the same issue here.

oleggromov avatar Feb 08 '19 23:02 oleggromov

I want to work on this issue, Can you assign me?

abhishek-kumar-91 avatar Oct 01 '23 17:10 abhishek-kumar-91

@abhishek-kumar-91 No, I will not assign. But you should feel free to work on this.

bitwiseman avatar Oct 13 '23 21:10 bitwiseman

@bitwiseman can I work on this issue?

Kyathirao avatar Nov 28 '23 03:11 Kyathirao

Yes.

bitwiseman avatar Nov 28 '23 03:11 bitwiseman

@serhiyupw I don't think that applies here. HTML entity tags don't get interpreted in comments and the issue isn't what is inside the comment tag but its positioning due to elements outside the tag.

bitwiseman avatar Nov 28 '23 23:11 bitwiseman