0

I'm trying to edit HTML in a Javascript file using template string literals but I'm unable to get all the same features like I would in an HTML file.

return (template string quotes) <p>Hello World</p> (template string quotes)

I've tried using extensions and the syntax highlighting works but formatting with prettier and emmet snippets doesn't work:

div#idName or div.className or ul>li*3 all don't work.

WebStorm has syntax highlighting and emmet snippets but no formatting. However, I'd prefer using VS Code. If anyone knows a solution I'd be extremely grateful!

Edit: I'm using Vanilla Javascript.

10
  • Is this actually a react file? Commented Jun 24, 2021 at 4:48
  • @Teemu No, Vanilla Javascript. Commented Jun 24, 2021 at 5:05
  • Then you've to wrap everything outside of the templates in quotes, or maybe rather create a single template string. If you'd just show a real code ... Also, you say it's vanilla JS, "html" is not a keyword in JS. Commented Jun 24, 2021 at 5:06
  • 1
    Does this answer your question? How to interpolate variables in strings in JavaScript, without concatenation? Commented Jun 24, 2021 at 5:34
  • Take a look at the link above, it should help. Commented Jun 24, 2021 at 5:34

1 Answer 1

2

I've solved emmet snippets in JS by editing the VS Code Emmet Include Languages settings.

YouTube: Enable emmet abbreviations in any language

Using an extension for syntax highlighting (lit-html or es6-string). Only thing I couldn't figure out is code formatting with Prettier for the html inside JS. Will update if I do.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.