Extra spaces in html tagged templates
See original GitHub issuePrettier 1.19.1 Playground link
--parser babel
Input:
const label = html`<span>${text}</span>`;
Output:
const label = html`
<span>${text}</span>
`;
Expected behavior:
Adding whitespace inside the tagged template literal affects the output. To avoid the spaces around my components, the only way right now is to add ignore comments.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:9 (7 by maintainers)
Top Results From Across the Web
4 Easy Ways to Insert Spaces in HTML - HubSpot Blog
The simplest way to add a space in HTML (besides hitting the spacebar) is with the non-breaking space entity, written as or...
Read more >21 Using template literals and tagged templates - Exploring JS
Before we dig into the two features template literal and tagged template, let's first examine the multiple meanings of the term template.
Read more >How to create string with multiple spaces in JavaScript
With template literals, you can use multiple spaces or multi-line strings and string ... You can use the <pre> tag with innerHTML.
Read more >Template literals (Template strings) - JavaScript | MDN
Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded ...
Read more >Handling whitespace in ES6 template literals - 2ality
A tag function like common-tag's stripIndent can help: ... Additionally, leading and trailing whitespace is trimmed.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That doesn’t even need an option then! Sounds good to me 👍
@saschanaz I’d vote to keep it simple: if the user tries to have it as one-liner and the line is not too long, avoid adding the line breaks. Otherwise leave the default formatting behavior.
This will create an incentive to the user to simplify their content, possibly extracting it into simple variables that would be easier to read.
It then will behave in a similar way as this example:
What do you think?