question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for this.html in addition to html for tagged template literals

See original GitHub issue

It’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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fiskercommented, Jun 30, 2020

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 a this. in front of html and css respectively. Several frameworks use class methods for their html and css functions.

Actual Behavior

html`
<div>
  <p>text</p>
</div>
`

Requested Feature

this.html`
<div>
  <p>text</p>
</div>
`

What do you think? Thank you!


Original post by @timonson in #8672

1reaction
davidmerriquecommented, Feb 14, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found