Add range ignore support for html languages.#6693
Add range ignore support for html languages.#6693voithos wants to merge 5 commits intoprettier:mainfrom
Conversation
4a773cb to
04e73bf
Compare
|
This PR has one problem that I can't seem to figure out: the |
This adds support for the prettier-ignore-start and prettier-ignore-end comment markers in html based languages, allowing prettier to preserve existing formatting of multi-element sections of code. Fixes prettier#5508.
04e73bf to
ba7821b
Compare
|
I played around with it a bit more, and made some changes that fix the issue I described earlier! Unfortunately, it feels somewhat hacky, although I can't think of any actual corner cases off the top of my head? Any thoughts welcome. |
|
@ikatyang Since you implemented the HTML printer, and the markdown printer which supports range ignore, could you review this please? |
|
Friendly ping? |
| * the child should process normally. | ||
| * @return {'ignore' | 'continue' | Doc} | ||
| */ | ||
| function maybeIgnore(path, index, ignoreRanges) { |
There was a problem hiding this comment.
Let's move this to util
There was a problem hiding this comment.
It's a bit difficult to move this as it uses variables from outer scopes and the doc builders. Other functions in utils don't use the doc builders. Let's keep it as is.
alexander-akait
left a comment
There was a problem hiding this comment.
Can we add strange test like:
<div><!-- prettier-ignore-start --></div><!-- prettier-ignore-end -->
<div><!-- prettier-ignore-start --><span>test</span></div><!-- prettier-ignore-end -->|
👋 Alan here from ampproject/amphtml. We love Our blocker is that our documents hold something we call the "AMP boilerplate", which is a standard and specific subtree: a In our ecosystem this subtree is usually written as one line, which is commonly pasted or automatically inserted in documents. This change would allow us to use Please let us know how we can help to get this merged! |
|
Could you include a |
|
Thanks for the suggestion. That can work, but we're avoiding it since we'd still like to keep the boilerplate's ignore section explicitly scoped. <!-- prettier-ignore-start -->
<style amp-boilerplate>/* ... */</style><noscript><style amp-boilerplate>/* ... */</style></noscript>
<!-- prettier-ignore-end -->vs <!-- prettier-ignore -->
<style amp-boilerplate>/* ... */</style>
<!-- prettier-ignore -->
<noscript><style amp-boilerplate>/* ... */</style></noscript>The boilerplate is often pasted, or new authors might see it and be unsure what it is. I worry that splitting it might create confusion, especially since we "validate" for its presence on every doc. |
|
Hey, sorry for the radio silence on this, but thanks for making the fixes to this! Let me know if there's anything I can do to help this get merged. 👍 |
|
This PR needs 2 more reviews from the collaborators. Besides, this is a feature, and there are fixes in |
alexander-akait
left a comment
There was a problem hiding this comment.
Looks good
/cc @prettier/core
j-f1
left a comment
There was a problem hiding this comment.
Bug:
Prettier pr-6693
Playground link
--parser htmlInput:
<div>
<!-- prettier-ignore-start -->
<span>
Test</span><!-- prettier-ignore-end -->
<!-- prettier-ignore-start -->
<span>
Test</span>
<!-- prettier-ignore-end -->
</div>Output:
<div>
<!-- prettier-ignore-start -->
<span>
Test</span>><!-- prettier-ignore-end -->
<!-- prettier-ignore-start -->
<span>
Test</span><!-- prettier-ignore-end -->
</div>
thorn0
left a comment
There was a problem hiding this comment.
Bug # 2 (whitespace is lost between the spans):
Prettier pr-6693
Playground link
--parser htmlInput:
<div>
<!-- prettier-ignore-start -->
<span>Test</span>
<!-- prettier-ignore-end --><span>2</span>
</div>Output:
<div>
<!-- prettier-ignore-start -->
<span>Test</span><!-- prettier-ignore-end --><span
>2</span
>
</div>|
@voithos Do you plan to fix the bugs found above? If not, we can probably ask @alanorozco to look into them. |
|
Hello! Yep, plan on taking a look soon. |
|
Welp, super late response to this, but I still haven't managed to find the time/motivation to pick this up again. :\ Really sorry about that. That being said, feel free to have someone else take a look at fixing the remaining bugs and getting this merged, if the desire is still there. 👍 |
|
@voithos Okay, thank you. Let's keep this PR open, remove from 2.1 milestone. It may be good to put |
|
bump |
This adds support for the prettier-ignore-start and prettier-ignore-end
comment markers in html based languages, allowing prettier to preserve
existing formatting of multi-element sections of code.
Fixes #5508.
docs/directory)CHANGELOG.unreleased.mdfile following the template.✨Try the playground for this PR✨