17

Is there any Vs Code extension to syntax-highlight HTML inside JavaScript strings?

Specifically I am writing web components

const html = content => `
  <div>
    <table>
      ${content}
    </table>
  </div>
`;

class BaseTable extends HTMLElement {
  constructor() {
    super();
  }

  set content(value) {
    const template = document.createElement('template');
    template.innerHTML = style + html(value);

    this.attachShadow({ mode: 'open' });
    this.shadowRoot.appendChild(template.content.cloneNode(true));
  }
}

I want string inside html constant variable to be highlighted

Gama11
  • 31,714
  • 9
  • 78
  • 100
Nurdaulet Shamilov
  • 446
  • 2
  • 6
  • 14
  • Just FWIW, that isn't a string, it's a template literal. (Untagged template literals *result* in strings, though. Tagged ones may not.) But I'd expect anything up-to-date that syntax highlights HTML in strings would also handle template literals. – T.J. Crowder Feb 13 '20 at 12:03
  • 4
    For future readers: you can use the plugin es6-string-html to highlight HTML template strings prefixed by a comment: `/* html */\`

    Hello world

    \``. There are es6-string-* plugins for other languages too, like CSS and Markdown.
    – ezekg Apr 20 '21 at 02:29

1 Answers1

10

If you use lit-html, There's a plugin in vs code called lit-plugin for syntax highlighting. Syntax is,

const markup = content => html`
  <div>
    <table>
      ${content}
    </table>
  </div>
`;

screenshot

vishnu v
  • 313
  • 4
  • 10