-
Notifications
You must be signed in to change notification settings - Fork 136
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
Javascript html parser to generate j2html from snippets #225
Comments
I could help with that :) |
Cool ! I'll get started this weekend then |
I'm almost done with the parser, I'm doing some tests. In one test, I'm starting with some input html, translating it to j2html with the tool I wrote, executing and rendering the html in java, and looking in the browser if it looks the same as the input. But I'm having an issue where I have a spaces missing. I think it might be a bug/unintended behavior in j2html render() and .renderFormatted() don't produce exactly the same page when viewed in a browser. There are single space differences is this intended ? |
Also a few attributes have small issues: The attribute 'autocomplete', as in input().withCondAutocomplete(true), seems to be considered a boolean by j2html, it takes a boolean param. But the mozilla docs say it's not just a boolean: valid values are "off", "on", "name", "email", "new-password", etc. There is also an issue on the the attribute onvolumechange. Instead of a withOnvolumechange, j2html has audio().withOnvolumechanged("value"), with a d at the end, that doesn't exist in HTML5 These 2 issues weren't blocking for me, I let these two attributes be mapped to the default case attr("key", "value") in the code generator so that it works regardless of what the input contains |
The difference is likely the whitespace formatted rendering introduces:
vs.
That whitespace will be interpreted by the browser as the extra space that you see. |
Thank you for pointing these out. I'll break these into separate issues to track for the next release. |
yes that seems to be what it is that poses some questions in terms of code generation though let's say I'm receiving the input
The text that I'm getting from KSoup is correctly
which is fairly ugly, but would not make people html look different than what they inputed to the generator Based on
I could write some logic and replace the multiple whitespace characters by a single space in some cases, which would produce
which looks better, but is maybe more complex than we'd like In my previous sanitization attempts, I would have generated
and the results would look different depending on wether render() or renderFormatted() is used Edit: fix github formatting |
This is a tricky question that I don't have a perfect answer for. I'd suggest that you detect newline characters, which probably indicates that formatted rendering is desired, and strip out the unnecessary whitespace from the inputs. That whitespace will be added back in when using |
Thanks, I implemented that. I'm preparing the pull request |
Is this work still under development and being worked upon? Do we expect this to be available as part of main release? |
The actual work is done, the code in the PR is usable In the discussion it ended up being a lot of code to maintain, so the idea is that I make a separate repository to maintain it myself, and push the transpiled javascript to npm, so that it can be used in the website as a js dependency. So it won't be part of a release of j2html and the PR could be closed. Time and energy has been a bit scarce on my end since the birth of my daughter, I'll get around to set up the new repo and npm as soon as I can |
If I embark on trying to create a js parser to parse html snippets into j2html code, would there be interest in adding that to the website ?
I'm thinking of doing that in kotlin using KSoup, and then compile that kotlin to javascript.
I hope this project is still active
The text was updated successfully, but these errors were encountered: