-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[WIP] feat: html support #4753
[WIP] feat: html support #4753
Conversation
placeholder="Enter email"> | ||
|
||
<small id="emailHelp" | ||
class="form-text text-muted">We'll never share your email with anyone else. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn’t be broken onto multiple lines unless it goes over the print width.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@j-f1 I know that there are a lot of problems, so I will assign a review from the main developers when I finish this, now it's just for feedback
0de972e
to
ef5e75c
Compare
What is the plan for handling whitespace? (I guess the code tells, but I'm too lazy.) In theory we can't change anything, because |
@lydell looks like we should output this as is, it is impossible to solve, also i think we should release html asap, it is allow to get feedback from people and maybe we have new ideas how to solve this |
ef5e75c
to
cce54f6
Compare
Simple instructions on how to try this? I'd happily provide feedback after formatting my codebase. |
@gabrielmaldi |
00e5ab4
to
00426cd
Compare
@j-f1 thanks! I'm constantly getting |
@evilebottnawi Would it be possible for you to avoid squashing your commits? It makes it harder to see what’s been changed since earlier and review those changes. Also, GitHub automatically squashed commits together when we merge the PR, so it doesn’t help keep the commit history any cleaner than it already is. |
fa6a696
to
21480de
Compare
@j-f1 👍, just squash PRs whats is look very bad (all first PRs look very bad 😄 ), no squash after last PR |
@j-f1 Can we rename |
Vote 👍 for indenting |
@j-f1 feel free to rename it to just glimmer, it’s no longer exactly compatible with handlebars |
For whitespace, we should figure out a way to opt-out for specific places. The trick I used to do was: <ul><!--
--><li>First</li><!--
--><li>Second</li><!--
--></ul> It’s not pretty but it let me indent things without introducing whitespace when needed. The second thing we need to have a documentation page about it and put a lot of warnings saying that unlike js, pretty printing a whole html folder is not safe because of this issue. |
One tool that would be useful is to print all the places where prettier would add/remove whitespace in an easily digestible format so that you can manually inspect them when doing the big codemod. |
@vjeux I don't know if it matters, but your trick introduces new comment nodes to the DOM tree, which may not be desired if you're performing DOM manipulations via JavaScript. An alternative, which I usually use, is: <ul
><li>First</li
><li>Second</li
></ul> Not the prettiest thing, but it shouldn't have any side-effect, afaik. |
@vjeux I agree about note in some case prettify is no safe, especially when you use
Any objections? |
Vote 👍 for indenting inside |
Vote 👍 for insert newline after script and style tags and 👎 for not or ❤️ print as in source <script>
alert("test");
</script> vs <script>alert("test");</script> |
Let's avoid this voting game. Can you make decisions based on what you believe should be done and then we can revisit based on feedback we get and running in existing codebases. |
@vjeux ok |
I forgot about prettier-ignore. This is indeed a good solution for whitespace in those cases. |
42cddd7
to
b2c368a
Compare
b2c368a
to
61f81a1
Compare
@ikatyang Can we merge this PR as is? I remove |
(isLineNext(children[1]) || isEmpty(children[1])) | ||
) { | ||
children.shift(); | ||
children.shift(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test for this double shift
thing? I'm not sure why we need it; removing [1]
and the second shift
does not affect any snapshot.
@@ -3,12 +3,15 @@ | |||
function parse(text /*, parsers, opts*/) { | |||
// Inline the require to avoid loading all the JS if we don't use it | |||
const parse5 = require("parse5"); | |||
const htmlparser2TreeAdapter = require("parse5-htmlparser2-tree-adapter"); | |||
|
|||
try { | |||
const isFragment = !/^\s*<(!doctype|html|head|body|!--)/i.test(text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⬆️ (This can be handled in other PR.)
: indent(children), | ||
n.children.length ? concat([softline, "</", n.name, ">"]) : hardline | ||
children.forEach(child => { | ||
multilineChildren.push(child); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multilineChildren
seems unnecessary, it's just an alias for children
.
|
||
if (!parentNode || !parentNode.sourceCodeLocation) { | ||
return n.key; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's possible to trigger, could you add a test for it?
return ( | ||
node.type === "attribute" && | ||
[ | ||
"allowfullscreen", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reference for these attributes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're marked as "Boolean attribute" here:
https://html.spec.whatwg.org/multipage/indices.html#attributes-3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Added in a5cecbd.
@ikatyang i am glad to fix your comments, but i really don't have time 😞 I think other developers can solve this and add more tests |
I think it should be fine to merge, @j-f1 any thoughts? |
If we’re not putting it in the production version, let’s merge! |
@evilebottnawi Is there a list for what haven't been done here? It'd be helpful for future work. |
I've tried using this to prettify some Ractive templates, but it seems it converts all elements to lowercase? e.g. |
@ikatyang no, but known problems:
|
Not sure if this is even supposed to work for frameworks template yet but i tried with angular templates other than that i think its working! |
Opened #5098 to track HTML issues that should be done before the public release, please comment there if you find something unexpected. |
Partial #1882
Feedback welcome.
How to use:
NOTE: you need to pass
--parser parse5
to enable it.Initial style preference questions:
head
andbody
tags insidehtml
or notscript
andstyle
tags or notscript
andstyle
tags or not