-
Notifications
You must be signed in to change notification settings - Fork 37
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
🐛 BUG: Formatter adds significant whitespace inside expressions #308
Comments
Another example, which adds visible whitespace between a link and a following comma: ---
const val = true;
---
{
val ? (
<p>
Things before the link.
<a id="long-id-that-makes-things-wrap" data-more="even more content"
>content of the link</a>,
things after the link.
</p>
) : null
} |
Arf, this one is gonna be quite hard to fix because inside expressions, we use a JavaScript (and as such, JSX) parser and the whitespace rules are different from Astro's (which are closer to HTML's) I'm not quite sure at the moment on how to proceed with fixing this. Sorry for the inconvenience! |
withastro/astro#6011 (comment)
… whitespace which prettier will put back … Workaround: <div class="cta__inner flow">
{/* prettier-ignore */}
<h2
class="cta__heading headline"
data-highlight="quaternary"
>{cta.title}</h2>
<p class="cta__summary measure-short">{cta.summary}</p>
</div> otherwise it ends up as <div class="cta__inner flow">
<h2
class="cta__heading headline"
data-highlight="quaternary"
>
{cta.title}
</h2>
<p class="cta__summary measure-short">{cta.summary}</p>
</div> which leads to undesirable results with something like .headline::after {
content: ".";
} Update: At times |
* use videos as gifs? * use bun * update bun * work on write-up and add gif * use mp4 instead (fixes safari) * have most things done, stupid mp4 * finish up * upgrade deps * remove whitespace from links see withastro/astro#6011 (comment) and withastro/prettier-plugin-astro#308 * fix links adding whitespace * make it make sense
Eeek, the ignore statements didn't work for me, are there any tips for interpolating strings, I'm inserting a link in an injected string
For now I will just not use underline... |
What about giving a try to dprint with markup_fmt? It has Astro support and that plugin doesn't encounter this problem. |
Still having the same issue with Astro 4.8.2. When using |
This syntax worked for me to ignore it. It was the only way I could figure out to not have whitespace between the date and the closing bracket. Would be nice, if we had a better way to do this, though: <somehtml>
{
frontmatter.updated && (
<>
{/* prettier-ignore */}
<span class="ml-6">
(updated
<time class="font-mono" datetime={frontmatter.published.toISOString()}>
{frontmatter.published.toISOString().slice(0, 10)}</time>)
</span>
</>
)
}
<somemorehtml> |
I will try and see if I can get anywhere with this issue and possibly open a PR at some point. Feel free to also look at it in the meantime, but please tag me if you also get close to opening a PR so we don't spend time solving the same issue. |
Describe the Bug
In JSX inside a
{var.map(e=><elem>{field1}{field2}</elem>
, the formatter adds newlines between the replaced fields even if they started without whitespace between them. Depending on the field content, this can be visible in the rendered output.Steps to Reproduce
npm init astro
using the default options.npm i --save-dev prettier-plugin-astro prettier
in the resulting directory.src/pages/index.astro
to start with:npx prettier -w .
Notice that there's now a newline between
{"To get started, o"}
and{"pen the directory"}
.The text was updated successfully, but these errors were encountered: