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

Add html highlight to angular component template #818

Closed
basarat opened this issue Jan 15, 2016 · 16 comments
Closed

Add html highlight to angular component template #818

basarat opened this issue Jan 15, 2016 · 16 comments

Comments

@basarat
Copy link
Member

basarat commented Jan 15, 2016

This can be added as demonstrated here : #798

That work was dropped with v8.0.0 when we moved to a Microsoft maintained text mate grammar. We have a script https://github.com/TypeStrong/atom-typescript/blob/5dfdd68497a0b3b3a7d6bc3575c223400ef29f0b/scripts/grammar.js (run using npm build in our project root) that contains any custom rules.

The custom template rules need to be added to grammar.js 🌹

@blakeembrey
Copy link
Member

@salvdev
Copy link

salvdev commented Mar 4, 2016

Is there anyway to get html highlighting in between template: yet?

@Jonatthu
Copy link

Excuse me I can't figure out how to add the html syntax highlighted in ts files when you write templates in the middle of these --> ``
I already replace the grammar.js and run build in the root of the project atom-typescript but nothing happened. What now?

Is there any tutorial for add this feature?

@daslicht
Copy link

So does that men we get syntax highlight in template strings using Atom now ? as described here:
microsoft/TypeScript#6508

?

@MarkPieszak
Copy link

@basarat Was this ever added somehow to Atom? Would love template highlighting! 👍

@GregOnNet
Copy link
Contributor

@blakeembrey I started to integrate the grammar you have mentioned: https://github.com/billti/TypeScript-TmLanguage/blob/ngml/TypeScript.YAML-tmLanguage#L507

Problem

Unfortunately the linked grammar does not work if there are any html attributes in the template.

book-details_component_ts_ __users_gregor_development_projects_angular_book_book-monkey2

Question

Do you know of a updated grammar source we could use?

My approach

I simply downloaded the language within scripts/grammar.js and merged the ng-grammar into the official grammar provided by Microsoft.

@blakeembrey
Copy link
Member

@GregOnNet Maybe you can mark it as the built-in HTML grammar?

@GregOnNet
Copy link
Contributor

Yes, I will try.
Thanks for your advice.

Kinds
Greg

@GregOnNet
Copy link
Contributor

Looks good so far.
I attached the following picture to demonstrate that the whole HTML-Highlighting is working.

book-details_component_ts_ __users_gregor_development_projects_angular_book_book-monkey2
(Do not use script and style tags in your inline templates. It is just a demo)

GregOnNet pushed a commit to GregOnNet/atom-typescript that referenced this issue May 13, 2016
GregOnNet pushed a commit to GregOnNet/atom-typescript that referenced this issue May 13, 2016
@MarkPieszak
Copy link

Can we play around & test this implementation if we update Atom typescript @GregOnNet ? Wow nice job guys 👍

@GregOnNet
Copy link
Contributor

@MarkPieszak Thanks,

I created a pull-request and hope it will be merged soon: #948

If you want to test this feature you only have the possibility to clone atom-typescript, checkout my branch and link it manually into Atom.

Kinds
Greg

basarat pushed a commit that referenced this issue May 14, 2016
* Adds custom grammar enabling html syntax highlighting
Applies for @component decorator provided by Angular 2
#818

* Applies grammar for html syntax highlighting to ts.cson and tsx.cson
This is done by running `npm run build`
#818

* Allows backticks inside html-templates without breaking syntax-highlighting

* Updates TypeScript grammar based on grammar.js
Done by running npm run build
@basarat
Copy link
Member Author

basarat commented May 14, 2016

@bennypowers
Copy link

This only works for properties called 'template' inside of objects.

but:

var someHtml = `<p>a template</p>`; //doesn't wotk
var myObject = {
  template: `<p>this works</p>`, //works
  myHtml: `<p>this doesn't</p> //doesn't work
};

@lukescott
Copy link

Now that atom-typescript uses atom's built-in language-typescript grammar this feature seems to have gone missing. Would it be possible to add a grammar that imports atom's language-typescript and adds the html rule? This would be useful for maintaining old angular projects.

@lierdakil
Copy link
Collaborator

We don't currently have the resources to maintain the grammar, sorry. And upstream isn't too keen on including this either.

It should be possible to write a grammar injection though. If you want to try your hand at that, you can take a look how Atom's TODO injection grammar does that: https://github.com/atom/language-todo

@colingm
Copy link

colingm commented Oct 18, 2018

So I went ahead and got a basic grammar injection for this that checks both ts and js files for inline template and styles where it can then use the default html/css grammar rules. Feel free to use it or open PRs to make it better. I didn't put that much time into it so I'm sure it could be improved:

https://github.com/colingm/language-angular-inline
https://atom.io/packages/language-angular-inline

@TypeStrong TypeStrong locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests