-
Notifications
You must be signed in to change notification settings - Fork 467
Add native XML Formatter #2453
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
Comments
I don't have time right now, but this is a great idea. We're also using spotless and would also like to format xhtml. We tried the Eclipse HTML/XML formatter that's integrated with spotless, but had to disable it because it breaks some inline JS/CSS. |
@jbrower2 did you test your formatter to make sure |
It's probably fine with regards to CSS and JS. The problem with the Eclipse formatter in spotless was that it tries to format JavaScript and CSS in style attributes, style tags, and script tags as JavaScript and CSS. From what I can tell, the browser2/xml-formatter just treats it as plain text content. If anything, I'd be a bit more worried how battle-tested it is. The parser code seems to be custom written and while to me it generally looks quite well written, from my understanding XML is also fairly complex with edge cases to consider. But I guess any potential bugs can always be fixed. |
The JS will be treated as plain text in this case, and I'm not doing any transformation on plain text. I don't have a unit test for that yet but I'll add one today, good thinking. |
I definitely agree with this. I tested it on a few closed-source projects so far. I'll be testing it on a few open-source repos in the near future, and if it can parse and format everything in those repos, hopefully we can consider it reasonably battle-tested. @blutorange & @melloware, let me know if there are any repos you want me to test it on. I'll be pushing updates to forks of these repos today. Here's a (whitespace-ignored) comparison of the PrimeFaces repo, after formatting with the default settings. I had originally omitted implementing |
@jbrower2 a good one to test on is the PrimeFaces Showcase: https://github.com/primefaces/primefaces/tree/master/primefaces-showcase |
That's buried in the diff I sent above, here's a direct link to the |
Nice! |
This would be a great addition, happy to take a PR which adds it. |
I've been a little slow to get this process moving, I haven't published to Maven Central before, but here's that: https://central.sonatype.com/artifact/com.jeffbrower/xml-formatter/1.0.0/overview I started working on adding a FormatterStep for this, using |
We have a zero dependency 100% Java XML formatter here which respects the same configuration options as
prettier
but does not requirenpm
and dealing with npm install especially in firewalled clients.Formatter.format - https://github.com/jbrower2/xml-formatter/blob/main/src/main/java/com/jeffbrower/Formatter.java
Checker.check - https://github.com/jbrower2/xml-formatter/blob/main/src/main/java/com/jeffbrower/Checker.java
We think this would be a great native XML formatter as we use Java Server Faces are are using this to format our XHTML pages across projects in a standard format.
@nedtwigg do you think this would be acceptable to donate?
@blutorange i may ask for your help 😄
The text was updated successfully, but these errors were encountered: