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

weird, outlandish wrapping with HTML Pretty Diff #735

Closed
garretwilson opened this issue Jan 8, 2016 · 6 comments
Closed

weird, outlandish wrapping with HTML Pretty Diff #735

garretwilson opened this issue Jan 8, 2016 · 6 comments

Comments

@garretwilson
Copy link
Contributor

The formatting seems all over the place. If I use JS Beautifier for XHTML, it incorrectly indents the entire document except for the XML declaration, as I reported in #706. So atom-beautify passed the buck and said it was JS Beautifier's problem, and told me to use Pretty Diff instead.

So I did, and Pretty Diff is Pretty Ugly. I start with this:

<p>For a computer program to be useful, it usually needs to gather input from the user, and also
  needs to provide output back to the user after processing. The approach it uses to interact
  with the user is called the <dfn>user interface</dfn> (UI) of the program. ...

Pretty Diff gives me this:

<p>For a computer program to be useful, it usually needs to gather input from the user, and also needs to provide output back to the user after processing. The approach it uses to interact with the user is called the
  <dfn>user interface</dfn>
  (UI) of the program. ...

What? Since when is <dfn> a block element? If Pretty Diff is behind in HTML4, then surely it has never heard of HTML5.

No, I don't intend to make special configuration files just to tell Pretty Diff that <dfn> should be inline. These sort of things are all over the place --- it's even wrapping <a>. Useless.

@prettydiff
Copy link
Collaborator

What? Since when is a block element?

Indenting a tag in the HTML code source has no bearing on whether the HTML tag is a block or inline element. The two code samples above render to exactly the same output in the browser unless the CSS property white-space is associated with the element. Pretty Diff does provide support for elements that should not have their contents modified: http://prettydiff.com/guide/tag_ignore.xhtml

it's even wrapping . Useless.

Both JS Beautify and Pretty Diff supply a wrap option. Set the value to 0 to turn wrapping off.

No additional action will be taken on this issue from Pretty Diff.

@garretwilson
Copy link
Contributor Author

Indenting a tag in the HTML code source has no bearing on whether the HTML tag is a block or inline element.

True. But that wasn't what I was asserting --- you have it backwards. Whether an HTML tag is a block or inline element should have a bearing on whether it is indented in the HTML source code.

The two code samples above render to exactly the same output in the browser ...

Of course! I could format the source code any old way, and it would still show up in the browser. But the whole point of a code formatter is that I want my source code to look pretty, too! (Um, isn't this obvious? If you don't want to make the source code pretty, what is the point of the prettydiff library?)

Pretty Diff does provide support for elements that should not have their contents modified ...

(sigh) Just like js-beautify (see beautifier/js-beautify#841), it seems you are conflating the concepts of "do not format" and "not a block element". Phrasing tags such as <dfn> should not have a line break added before them. That doesn't mean you should not format their contents. Those are two entirely separate concepts.

@prettydiff
Copy link
Collaborator

(Um, isn't this obvious? If you don't want to make the source code pretty, what is the point of the prettydiff library?)

The reason I indent even inline tags is to make the code easier to read. When tags are lumped into text they can get lost and become more difficult to quickly identify for human readers not using syntax color schemes. This is particularly true in long content that is not being wrapped. The goal is to make code easier to read opposed to increasing content legibility, which is where embedded inline elements would benefit. Content legibility is better discerned from the rendered product where various other pieces and interactions come together to influence how that content is consumed.

I come to this conclusion because I have maintained an HTML/XML beautifier/parser for almost 7 years and at one time supported beautification as you suggest. Experience proved that to be less than ideal provided large blocks of time examining a variety of code samples and use cases.

(sigh) Just like js-beautify (see beautifier/js-beautify#841), it seems you are conflating the concepts of "do not format" and "not a block element". Phrasing tags such as should not have a line break added before them. That doesn't mean you should not format their contents. Those are two entirely separate concepts.

From our perspectives, as the maintainers of large parsers, there is no difference. Code is parsed provided a set of rules. The parsed code is beautified according to a different set of rules. In the end there is only parsing and decoration. Everything else is completely superficial or irrelevant to the tools we maintain. What a given tag means or what it does to enhance and describe its content is for higher level assisting technologies not merely concerned with code beautification.

Another option to consider in the face of a difference of opinion is to write your own beautifier if that difference of opinion is an insurmountable roadblock. That is how Lamborghini got started: A mere tractor producer recommended some improvements to Enzo Ferrari because the transmission felt a little sluggish. Enzo told him to go build his own car if he knew better.

@garretwilson
Copy link
Contributor Author

Thanks for the thorough and nice response.

The reason I indent even inline tags is to make the code easier to read.

Fine. You like that. I don't. We have different preferences. So all I ask is a setting that allows me to specify tags that should not start with a linefeed and be indented (i.e. inline). Isn't that a reasonable setting to ask for? An option of "don't format this at all" is a different setting semantically, don't you agree?

@garretwilson
Copy link
Contributor Author

Another option to consider in the face of a difference of opinion is to write your own beautifier if that difference of opinion is an insurmountable roadblock.

Yes, sorry for taking up your time with this. The problem is that there are so many things for me to rewrite, because no one takes care in writing their software to specifications and they simply throw together a one-off solution that works specifically for their own situation. (Try getting a beautifier that understands the XML declaration in XHTML5 files, or that provides the correct EOL based upon the platform, for instance.)

@rickysullivan
Copy link

#778

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

No branches or pull requests

3 participants