-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Support formatting of HTML files #107
Comments
So far I could not find a promising Java implementation of a HTML formatter, please let me know if someone knows any. |
I wouldn't recommend to find one based on Java. Sure maybe there is one but for HTML, JS, CSS, Less, Sass, etc. there are node modules due to relies on it and it is a common web tech stack. So for formatting those files, there is a good one called prettier https://prettier.io/. If you search for prettier java you will find not that what you want, just a plugin for formatting Java code, but not written in java. So I would prefer to check whether it is possible with your plugin to implement this via node or not. I still have a plan to integrate prettier as a plugin for the web tech but lack of time, not soon unfortunately. |
I had a look into the repo of spotless and in the readme there is this: Isn't this looks promising for what you wanted? |
Hi @Chris2011 and thanks for your thoughts. Actually I had a look in Spotless quite some time ago (already using the DBeaver SQL Formatter from there) and didn't really understand how they support neither HTML nor CSS, therefore I decided to do it like they guys from the formatter-maven-plugin did with JSoup. But regarding CSS I decided to have another look into Spotless yesterday and saw in their _ext subfolder that they used the Eclipse CSS Formatter for that which is also quite interesting, I guess I'll have another look into that and see what I can do. Regarding prettier.io: I also looked into it and hoped I would find a Java-based implementation for it or at least some kind of wrapper, but I didn't and so I'm not sure if I really want to execute an external binary (npm) to format source code, it would be an option, but still I would need to check how well I can integrate it into the IDE. I might give it another shot though, but still I prefer the Java way, and - as said - Spotless seems very promising, maybe for even more languages. Cheers, |
Yes, you are right, spotless seems nice to have. Also as I said I will try prettier implementation sooner or later. It should be doable. There is also a plugin for eslint, finding bugs/stuff in js files so there is no problem to use an external CLI tool and create a wrapper with Java. |
That's true, but I prefer the plain Java way 😉 |
I just use ExternalExecuter and check the option from NetBeans node as far as I can remember. You can check this plugin: https://github.com/joakim-eriksson/nb-eslint or this one: https://github.com/Chris2011/NBAngularCLI/tree/develop |
@Chris2011 I just had a closer look into spotless and prettier. Regarding spotless I wasn't able to use their external libs based on the Eclipse formatters for CSS and HTML as it seems the Eclipse stuff needs some OSGi classes which I don't have. Regarding prettier.io: I could not find a way to call prettier with some string and get a string in return, it seems I can just call prettier with a file and it directly modifies the file then, but I neither like the idea of creating a temporary file every time I want to format code nor to save the changes of a file before calling prettier. Do you have an idea how I could manage that? I mean there seem to be integrations for IntelliJ as well as for VS Code and I don't think they will save the files before formatting as well, but still, I couldn't find anything which looks promising there. |
Thx for your deeper look, lemme check later how VS Code does this :). You can try to create an in memory file with the content of the original file, take the formatted content and remove the in memory file. Or is this what you said by creating a temp file? |
I also had a look into the prettier CLI. There is the range property: https://prettier.io/docs/en/options.html#range So if you don't want to create an in memory file you can take the text of the JEditor from offset 0 to length of file and take this instead of a file. But adding this instead of using a file can also lead to problems. I guess. So we have 2 options:
|
Yes, that's more or less what I meant with the temp file |
But the latter would only work if I could pass a String to the Prettier CLI, but as I understood, I have to pass a file path or am I wrong? |
Opened a new ticket regarding prettier.io #233 |
I didn't test it out yet how it directly works. |
No description provided.
The text was updated successfully, but these errors were encountered: