-
Notifications
You must be signed in to change notification settings - Fork 453
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 JS Beautify incorrectly adds newlines to list items #736
Comments
I really don't know where you're getting this behavior. This doesn't happen at http://jsbeautifier.org/, so @Glavin001 , I don't see how you can blame it on the underlying library. |
Please follow the guidelines outlined at https://github.com/Glavin001/atom-beautify/blob/master/CONTRIBUTING.md#new-issues-bugs-questions-etc specifically the steps regarding running command JS Beautify is an interesting case because it accepts all of the options and passes them directly to JS Beautify: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/js-beautify.coffee#L31
Hope that helps. |
I installed atom-beautify just this morning. No other settings were changed. Look, I'll update the description to show you how to exactly reproduce the issue with a fresh atom-beautify installation. If you can't reproduce it, sure I can go through all this stuff of debug, gist, debug.md, etc. But there should be no need. It should be reproducible fresh out of the box. I'll update the description with a small test case. |
I've updated the bug description. I've also realized that it is possible to supply a special .jsbeautifyrc configuration to the plugin, so in the meantime I'll explore which setting may be causing the problem. |
@Glavin001 , seriously, this is not working. Tell me what I'm doing wrong. I've created the following .jsbeautifyrc file:
Unfortunately the weird newlines I reported are still being added. (In fact my .jsbeautifyrc should be a moot issue---according to the site, It seems to think that things like |
This comment: #736 (comment) 😜
Atom Beautify passes the options as-is directly to js-beautify. See code at If you run After you have the final options as shown by
The conclusion will be one or more of the following:
|
Right, OK, fair enough. I was hoping it would just be something easy you could point out that I was missing. It's been a long, long, long day. I'll attack this tomorrow---after all the other work. Good night. |
OK, here you go @Glavin001 . https://gist.github.com/garretwilson/20f83510591908ba4c87 (A maybe-related question: is the atom-beautify wrap line length overriding that in my |
I can confirm the final options:
So I think it could be that an option is missing being set. Try the option
|
Your suggestion essentially to start randomly pushing buttons to see what changes is missing the bigger point here. I can take the original HTML presented in this issue (and in the Gist) and paste it at http://jsbeautifier.org/ and it formats correctly. atom-beautify does not format it correctly. Your assertion I thought was that if I don't send something strange in the config, then I should get the default beautify js output. But I'm not. So it remains to be seen why your plugin is getting different formatting results than the default beautify js output. There is no evidence that http://jsbeautifier.org/ is using any special "unformatted tags" settings. Moreover this is not an issue of turning off formatting for Please investigate and find out what settings http://jsbeautifier.org/ is using and find out what settings atom-beautify is erroneously sending (or not sending) to break the beautify output. This works on the http://jsbeautifier.org/ site with no indication that there they are using special lists of excluded elements. It breaks on atom-beautify. Without further evidence it would appear that atom-beautify is doing something wrong. Please investigate. |
I am in the middle of class right now and
The description of the option A quick search turns up the following js-beautify code: https://github.com/beautify-web/js-beautify/blob/bc5b7b5a3310df19cfe44489f3d0731d0c9b49cf/js/lib/beautify-html.js#L120-L122 unformatted = options.unformatted || ['a', 'span', 'img', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd',
'var', 'cite', 'abbr', 'acronym', 'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike',
'font', 'ins', 'del', 'pre', 'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; So the default options for ['a', 'span', 'img', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd',
'var', 'cite', 'abbr', 'acronym', 'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike',
'font', 'ins', 'del', 'pre', 'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']` Take note of this as we will get back to it later. I then looked at their website and found I ran Chrome debugger and it showed that
So the final piece to check would be the final options being passed to JS-Beautify. This happens at https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/js-beautify.coffee#L38 text = beautifyHTML(text, options) Now let's assuming there is a bug in Atom Beautify -- I would agree there is something strange going on. Guess what! The results are:
It turns out that the Furthermore, it also turns out that the real issue is the default option for
And the default option for Note the difference between:
and
See above that In summary, the bug in Atom Beautify is the defaults which were extracted from JS-Beautify's documentation at https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify-html.js#L66 The temporary solution until I publish a new version?
And set it to:
When a new release is published, this default option will be updated to reflect the new default of JS-Beautify's unformatted option.
If you think you have a better suggestion, then please feel free to debug on your own -- which you should be attempting already. My suggestion was to try an educated guess which takes little time to prove it's effectiveness. After you rejected my suggestion I tested it for myself, recognized that the assumption was correct and the Anyway, I have to get back to my class. |
Published fix to v0.28.21 |
Hi, @Glavin001 . First I want to say I greatly appreciate your taking the time to address this. I can certainly empathize with your being busy with classes. In fact the reason why I am overwhelmed myself is that I am teaching a class on Java, and moreover I am writing all the lesson materials. (The lesson materials are in XHTML5 and I have been struggling for weeks just to get the source code formatted, because I run into bugs in everyone's libraries at every turn.) As I had provided you sufficient information for you to reproduce the bug in your library, I imagined it would be more efficient for you to investigate your own code (as it was in fact) than for me to go on a "fishing expedition" trying changes in a codebase and library unfamiliar to me. I'm not being lazy---I would have looked into it more, but I was writing the lesson materials for the class I will give in two hours. Anyway, it looks like you found your bug, so I will give it a spin and see how far it goes. Thanks again and good luck with your class. |
(FYI, it looks like even js-beautify needs to update its list of inline elements; see beautifier/js-beautify#840 .) |
Go to http://jsbeautifier.org/ and paste the following in the Beautify text box:
The official js-beautify will give you the following:
But paste the same starting source code into Atom 1.3.3, install atom-beautify and make no changes, and hit
Ctrl+Alt+B
. atom-beautify will give you:Note how atom-beautify has incorrectly added newlines to the
<li>
. atom-beautify must be sending different options to js beautifier and/or doing extra processing.The text was updated successfully, but these errors were encountered: