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

Allow jsBeautify to be used for XML #369

Closed
moreginger opened this issue May 26, 2015 · 4 comments
Closed

Allow jsBeautify to be used for XML #369

moreginger opened this issue May 26, 2015 · 4 comments
Assignees
Milestone

Comments

@moreginger
Copy link

Beautification of XML used to use jsBeautify and it worked OK (apart from beautifier/js-beautify#683), in particular it has better options (then PrettyDiff) for attribute wrapping etc. Could it be made a settings option again.

@prettydiff
Copy link
Collaborator

Could you provide a code sample that you believe to be in error so that I may work on improving this for you?

Pretty Diff was chosen over jsBeautify because jsBeautify uses an HTML parser to provide incomplete support for XML. Officially, jsBeautify project does not support XML at all, though it sounds like they are working on this. The incomplete and hacky support for XML made it difficult to extend base XML support for various edge cases, templating schemes, and particuarly React JSX format. The straw that broke the camel's back for this project was an internationalization issue.

It is important to note that jsBeautify now provides for React JSX using a ES4X library to provide some JavaScript to XML conformance. Both projects based their support off this document that I assembled: https://github.com/prettydiff/prettydiff/blob/master/unit_tests/beautification_javascript_jsx.txt

The Pretty Diff approach is to provide a base markup parser then apply different rules for various different language formats. The Pretty Diff approach is not necessarily better or more stable but is certainly more extensible.

@moreginger
Copy link
Author

Thanks for the detailed answer!
Notably in jsBeautify you can force wrap one attribute per line to get something like:

<foo xmlns:ns1="ns1"
  xmlns:ns2="ns2"
  xmlns:ns3="ns3" />

...which can be easier to work with. It also allows the attribute indent size to be set separately to the standard indent.

I'm not sure whether I prefer the first attribute appearing on the same line as the tag name. I got used to it recently when using atom-beautifier/jsBeautifier, but the pretty printer I have previously used also put the first attribute on a separate line.

@Glavin001
Copy link
Owner

Since this issue is add XML language to JS-Beautify beautifier, here are instructions for what would need to be done and submitted in a Pull Request. It's very straight forward:

I will accept a pull request with the above implemented. Thanks!

@Glavin001 Glavin001 self-assigned this Jun 10, 2015
@Glavin001 Glavin001 added this to the v0.29.0 milestone Jun 10, 2015
@Glavin001
Copy link
Owner

Published to v0.28.1

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

3 participants