Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[angular] Syntax highlight for inline HTML templates #130

Closed
idooo opened this issue Nov 19, 2015 · 24 comments
Closed

[angular] Syntax highlight for inline HTML templates #130

idooo opened this issue Nov 19, 2015 · 24 comments
Assignees
Labels
*extension-candidate Issue identified as good extension implementation feature-request Request for new features or functionality javascript JavaScript support issues
Milestone

Comments

@idooo
Copy link

idooo commented Nov 19, 2015

It would be really cool if there was syntax highlighting and autocompletion for inline HTML templates

VS Code:
image

IDEA:
image

@zachlysobey
Copy link

With the recent VSCode update, this actually got worse for me.

My experience was similar to @idooo, but now I'm experiencing fairly major problems. See the screenshot below.

screen shot 2015-11-20 at 3 32 45 pm

I would absolutely LOVE if VSCode would syntax-highlight html in these multi-line strings. I think a MS rep said this was coming soon (at AngularConnect)...?

@aeschli
Copy link
Contributor

aeschli commented Nov 24, 2015

duplicate of #133

@aeschli aeschli closed this as completed Nov 24, 2015
@jbicks
Copy link

jbicks commented May 10, 2016

This is still an issue - yet it has been closed. So has the duplicate #133. Is this being addressed somewhere else, or can this be re-opened?

@aeschli aeschli reopened this May 10, 2016
@aeschli
Copy link
Contributor

aeschli commented May 10, 2016

You are right, there's more to do.

@aeschli aeschli changed the title Syntax highlight for multiline strings [javascript] Syntax highlight for inline HTML templates May 10, 2016
@aeschli aeschli changed the title [javascript] Syntax highlight for inline HTML templates [angular] Syntax highlight for inline HTML templates May 10, 2016
@aeschli aeschli added the javascript JavaScript support issues label May 10, 2016
@aeschli aeschli added this to the Backlog milestone May 10, 2016
@aeschli aeschli added the feature-request Request for new features or functionality label May 10, 2016
@aeschli
Copy link
Contributor

aeschli commented May 10, 2016

This is related to #2000 and #2793

@wmertens
Copy link

Also related to #5961 (which asks for broader, configurable support)

@kevjames3
Copy link

+1

@albertodenatale
Copy link

+1

3 similar comments
@ntziolis
Copy link

+1

@KTITS-Kevin
Copy link

+1

@zekida
Copy link

zekida commented Jun 21, 2017

+1

@zachlysobey
Copy link

@albertodenatale @ntziolis @KTITS-Kevin @zekida @kevjames3 please just subscribe and/or use reactions instead of +1s. When you do that it sends an email to everyone subscribed to this thread.

@trash
Copy link

trash commented Jul 18, 2017

This plugin seems to work pretty well in the meantime.

@doctorc30
Copy link

+1

@mjbvz mjbvz added the *extension-candidate Issue identified as good extension implementation label Aug 24, 2017
@mjbvz
Copy link
Contributor

mjbvz commented Aug 24, 2017

I've created an example extension that demonstrates how extensions can inject grammars into JS/TS template strings: https://github.com/mjbvz/vscode-js-template-string-grammar-injection-example

The example shows how colorizing two forms of html template strings can be supported, tagged templates:

html`<a>text</a>` 

and looking at the first character of the string body to see if it is possibly an html tag:

`<a>text</a>` 

The example example is not complete but it should give a starting point for extension authors to build on

@wmertens
Copy link

wmertens commented Aug 25, 2017 via email

@mjbvz
Copy link
Contributor

mjbvz commented Aug 25, 2017

This is a hard problem and I don't think VS Code can offer an automatic solution.

Consider a css template string:

const img = 'url(https://example.com/cat.png)';
const style = css`background: ${img} no-repeat;`

And let's say you have two grammars, VS Code's standard css grammar and one that parses ${...} expressions. I don't think VS Code can mechanically combine these grammars to parse the background: ${img} no-repeat; expression properly.

A few approaches that come to mind:

Run both grammars and then combine the tokens somehow

This doesn't work because the css grammar parses the string background: ${img} no-repeat; incorrectly:

screen shot 2017-08-25 at 11 18 14 am

Run the template expression grammar, then run the css grammar with template expressions removed

This works in some cases but not generally. In our example, I think this may work because the css grammar would see: background: no-repeat;. However, it is easy to come up with cases that break this:

const rule = 'background'
css`${rule}: red;`

Inject the template expression grammar into the css grammar

Depending on how this is performed, this may no not be a purely mechanical operation. Let's say you can use injection so that the css grammar knows that ${...} is a valid property value and a valid property name. That solves background: ${img} no-repeat; and ${rule}: red;, but break once you start getting more creative:

css`back${'ground:'} red

I actually don't think you can ever properly support that case though.

The core problem is that template expressions are operating at different level than the grammar, they are more like text macros from the css grammar's point of view.


I'd love to hear if someone has other suggested approaches here.

This example extension I provided shows how you can get a custom grammar to run inside the template string. It is then up the the grammar author to make sure JS template strings are properly handled inside their custom grammar. This may involve injecting the template grammar into a few rules, or it may require writing a completely new grammar

I've updated the example extension to show one way the injection can be done. The approach is similar to Atom's language-javascript grammar

@wmertens
Copy link

wmertens commented Sep 12, 2017 via email

@I-NOZex
Copy link

I-NOZex commented Sep 27, 2017

👍

@asfktz
Copy link

asfktz commented Oct 5, 2017

Hi, I only read this issue briefly so forgive me if it's not related.

Thought to share with you that I realized that this extension for angular 2 also works with angular 1
https://marketplace.visualstudio.com/items?itemName=natewallace.angular2-inline

image

@kevjames3
Copy link

kevjames3 commented Oct 5, 2017 via email

@aeschli aeschli added *extension-candidate Issue identified as good extension implementation and removed *extension-candidate Issue identified as good extension implementation labels Nov 20, 2017
@vscodebot
Copy link

vscodebot bot commented Nov 20, 2017

This issue has been closed because it is not within the scope of the core product, but could be addressed by an extension. The VS Code Marketplace shows all existing extensions and you can get started writing your own extension in a few simple steps. See also our issue reporting guidelines.

Happy Coding!

@vscodebot vscodebot bot closed this as completed Nov 20, 2017
@wmertens
Copy link

wmertens commented Nov 21, 2017 via email

@mjbvz
Copy link
Contributor

mjbvz commented Nov 21, 2017

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*extension-candidate Issue identified as good extension implementation feature-request Request for new features or functionality javascript JavaScript support issues
Projects
None yet
Development

No branches or pull requests