-
Notifications
You must be signed in to change notification settings - Fork 96
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
[Rough idea] Rework plugin #144
Comments
Giving the HTML parser I do think that overall this would be a much more maintainable solution if it could be gotten to work, but I don't see a clear way through here though. Is it important that the strings the HTML formatter are getting are the same length as what they're replacing? Would anything bad happen if they were longer? If not, that frees us up a bit in terms of making long, unique strings to search for afterwards. |
You are right about the tags, silly overlook on my side 😄 The |
As an alternative, would it be possible to do a Svelte AST-to-Prettier HTML AST translation? I haven't looked into this in detail, but I think it's only the node types that are different. If there is (or we add) a way to plug in handlers into Prettier for node types it doesn't know about, that would feel like a cleaner to solution. |
I don't think the HTML AST is public API, and if it changes we would need to make branches depending on the prettier version the user uses. Passing the text as is to the HTML parser will fail because that parser trips up on Svelte syntax. Also, the Svelte AST does lose some information, for example whether or not theres whitespaces/newlines between |
I found one more thing which would make this very hard to implement: We need the Doc output from the HTML parser to add our own formatting afterwards. But we cannot reliably parse out the stringified content from that, which we would need to replace parts with our own formatting. Example: {#if foo}
bar
{/foo} to <iiiif>
bar
</iiif> We would get some Doc-Builder-soup from which we need to know which parts form the If we on the other hand use the prettified string output from the HTML parser, we would get stuff like this <iii
>content</iif
> wich also will be hard to find and replace. Also the formatting might not be the same compared to using Docs for everything. |
Closing for the reasons outlined above, #160 will get us closer to how prettier formats html. |
Right now this plugin does HTML formatting itself, which means keeping up with Prettier upstream on their changes and reimplementing all the corner cases they already gone through, especially when it comes to whitespace handling.
For script/style this is not the case because their formatting is delegated to the built-in parsers.
I wonder if we could do the same for the markup part, like this:
{#if
are replaced with tagsExample:
Input
What the HTML parser gets:
What this plugin will have left to do:
{#if a}
transition:fade
{a}
Open questions
The text was updated successfully, but these errors were encountered: