Support for this.html in addition to html for tagged template literals
See original GitHub issueIt’d be handy for this.html
to also be formatted by prettier.
I use wicked-elements a lot and taking this example, it would be great if it was supported:
From wicked-elements repository
<div>import {render, html, svg} from 'lighterhtml';
const LighterHTML = {
html() { return render(this.element, html.apply(null, arguments)); },
svg() { return render(this.element, svg.apply(null, arguments)); }
};
import {define} from 'wicked-elements';
define('.my-component', {
...LighterHTML,
init() { this.render(); },
render() {
this.html`<h3>Hello 👋</h3>`;
}
});
</div>
Prettier 1.19.1 Playground link
--parser babel
Input:
html`<div>I look great!</div>`;
this.html`<div>I don't look so good</div>`;
Output:
html`
<div>I look great!</div>
`;
this.html`<div>I don't look so good</div>`;
Expected behavior:
this.html
should be supported also.
Thank you!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Tagged Template Literal for HTML Templates - Medium
Template literals are powerful for creating markup to display data. From there you can create DOM nodes and insert them in your document....
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 >21 Using template literals and tagged templates - Exploring JS
const html = tmplFunc(data);. A template literal is similar to a string literal, but has additional features – for example, interpolation.
Read more >Support `html` tagged-template-literals · Issue #35 · aca/emmet-ls ...
Please consider adding support for html-tagged template literals, such as you'd find with lit, FAST, htm, and others. Current Behaviour // example.js html` ......
Read more >Add support for tagged template literals language injection
Current behaviour: literal content is always treated as html (as I see emmet shortcuts for html and html highlighting works within a template)....
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
Now that
prettier
has implemented formatting for html and css code inside JavaScript/TypeScript tag functions I would like to request to expand this behavior to the same syntax but with athis.
in front ofhtml
andcss
respectively. Several frameworks use class methods for theirhtml
andcss
functions.Actual Behavior
Requested Feature
What do you think? Thank you!
Original post by @timonson in #8672
I’m totally fine with disabling it by default (which looks like it’s coming) and enabling via configuration.
It’d be a welcome enhancement if anything
foo.html`...`
would work.Thanks guys.