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

Disable/Skip HTML single-line comment #426

Closed
ghost opened this issue Mar 18, 2014 · 13 comments
Closed

Disable/Skip HTML single-line comment #426

ghost opened this issue Mar 18, 2014 · 13 comments

Comments

@ghost
Copy link

ghost commented Mar 18, 2014

I usually have a comment after the closing html tag in order to identify the tag on big files with a lot of tags.

Input:

<div class='panel'>
    ...
</div><!-- /.panel -->

Current output:

<div class='panel'>
    ...
</div>
<!-- /.panel -->

Desired output:

<div class='panel'>
    ...
</div><!-- /.panel -->

It would be nice if it would be able skip those single-line comments.

@ghost
Copy link
Author

ghost commented Mar 19, 2014

Maybe something like

ignore_pattern: "some regex"

@hectorpalmatellez
Copy link

+1 to this

@vongoh
Copy link

vongoh commented Sep 1, 2014

+1!

@dotnetsp2
Copy link

I like the ignore_pattern suggestion; to allow for multiple patterns, perhaps it would be better to change it to the following:
ignore_patterns: [ "some regex", "another regex", ... ]
Allowing for an array of RegEx patterns would allow developers to define several simple patterns, rather than long, complex patterns. Either way, I really like the ignore_pattern approach.

@bitwiseman bitwiseman added this to the v1.6.0 milestone Sep 30, 2014
@bitwiseman
Copy link
Member

We're not going to do a regex array (sorry folks, that's just crazy town frolics), but having single line html comments not get moved to a new line sounds totally reasonable.

@cjaoude
Copy link

cjaoude commented Jan 11, 2015

+1.

Sooner the better! :) much appreciated.

@olsonpm
Copy link
Contributor

olsonpm commented Feb 5, 2015

+1. My pragmatic use-case is the freaking html inline block spacing behavior. Basically in order to remove auto white-space between inline elements you need their tags to be together, which I normally accomplished via comments. The other workaround which has been driving me nuts was to set font size to zero. Now instead of inheriting a reasonable font-size, I inherit the font-size of zero and often forget about it days later causing me to say "hey, why isn't that element showing up?"

@olsonpm
Copy link
Contributor

olsonpm commented Feb 19, 2015

For those interested, I couldn't handle the "font-size: 0" hack anymore so I customized my beautify-html to the following:

// beautify-html.js, version 1.5.4, line 662

// CUSTOM
//
// Don't add newlines before or after comments with a third dash
//
var endComment = (this.token_text.slice(0, 4) === '<!---');
var lastTokenText = this.output[this.output.length - 1];
var beginningComment = (lastTokenText.slice(-3) === '--->');
if (!endComment && !beginningComment) {
    arr.push('\n');
}

The simple test I created was:

var commentIn = '<div class="ok"></div><!---\ndo not format\n---><div class="ok"></div>';
var commentExpected = '<div class="ok"></div><!---\ndo not format\n---><div class="ok"></div>';
assert.strictEqual(html_beautify(commentIn, opts), commentExpected);

The above is not tested very well, and I don't have time to spend making it suitable for an official PR. I will update the code here if I find any bugs.

Edit:
I realized how convenient it was to have regular comments be formatted, but comments with a third dash stay put. The above code has been changed to reflect that.

@bitwiseman bitwiseman modified the milestones: 2.0.0, v1.6.0 Jan 27, 2016
@stevgouws
Copy link

Hi any news on if this option will be added? Would be great. Thanks.

@THavas
Copy link

THavas commented Nov 18, 2016

+1 yes please. Love Beautify but hate having my ending div comments on a new line.

@mahmoudzadah
Copy link

Was this resolved? I am interested in this.

@bitwiseman
Copy link
Member

@mazadah
This is still open and waiting to be implemented. The three-dash structure proposed by @olsonpm would be one way to do this to start with. That change would be non-breaking, but would require people to do something different with their html.

Having single-line comments (comments whose contents do not include a newline) stay on the same line would also be reasonable. It might also be reasonable to have the rule be that a closing tag followed by a comment, followed by a newline should not be moved.

@bitwiseman
Copy link
Member

This is fixed in 1.8.0 as #1337

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

No branches or pull requests

9 participants