Highlight HTML syntax inside a string?
Asked Answered
I

4

35

Is there a way (plugin, option, or tip and trick) to highlight HTML syntax in a JS string?

My document is a .js file, in which I use strings containing HTML code. Is it possible to highlight HTML syntaxe inside these strings?

enter image description here

Inactivate answered 8/3, 2018 at 5:53 Comment(3)
Welcome to SO. I took the liberty to rephrase your question so that is more easily readable.Harneen
ok thank, english are not my natal language sorry for mistake.And stackflow delete some work like HI !Inactivate
No problem :) And I would not call it a mistake. SO tries to focus on the questions and greetings, thanks etc. are considered irrelevant to the question (fluff).Harneen
I
51

You can use the extension es6-string-html

Note: You need to add a comment with the language in front of the multiline string

Before and After

Inactivate answered 8/3, 2018 at 13:52 Comment(2)
Sadly it doesn't appear to help with intilisense :(Gradate
intilisense is run by ts-server and its not process any stringsInactivate
R
10

The extension that you suggested requires that you prefix your strings with a comment like /*html*/ or html. I'm working with Angular, and I didn't want to go through all my templates to prefix them, so I found this extension that does it automatically without prefixes:

https://marketplace.visualstudio.com/items?itemName=natewallace.angular2-inline

It is included in the Angular Essentials package by John Papa:

https://marketplace.visualstudio.com/items?itemName=johnpapa.angular-essentials

Radon answered 24/10, 2018 at 8:46 Comment(1)
perfect! it works for any js file, not only for Angular :)Aside
D
2

You can try the extension leet-html. It works fine, without any prefix or comment to add, and not related to any framework.

enter image description here

Digged answered 12/3, 2024 at 21:29 Comment(0)
S
0

For Vue try Vue Inline Template:

https://marketplace.visualstudio.com/items?itemName=faisalhakim47.vue-inline-template

Simony answered 17/6, 2021 at 7:51 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.