Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Atom HTML syntax highlight in template literals (for angular2)

How can I get HTML syntax highlight in template literals?

Something like this which I've wrote for sublime before:
Here is sublime version https://github.com/Microsoft/TypeScript-Sublime-Plugin/pull/189/files
How can I write the same thing for Atom?

enter image description here

like image 643
amin Avatar asked Apr 18 '16 17:04

amin


1 Answers

I was able to achieve this, here is the gist for ts.cson file.
form atom typescript plugin on my system:
/Users/amin/.atom/packages/atom-typescript/grammars/ts.cson

https://gist.github.com/aminroosta/509476f48f05f4b56db2c0748fedc8fd

This is very useful for angular2 development,
here is an screenshot for atom with html and css highlights:

enter image description here

I couldn't find a better regex to match against template: and styles:[, if anyone can come up with a better regex i will accept their answers.

the important changes in ts.cson file are:

"template-html":
  name: "meta.template.html.ts"
  begin: "`<!---->"
  beginCaptures:
    "0":
      name: "string.quoted.template.ts"
  end:"`"
  endCaptures:
    "0":
      name: "string.quoted.template.ts"
  patterns: [
    {
      include: "text.html.basic"
    }
  ]
"template-css":
  name: "meta.template.css.ts"
  begin: "`/\\*\\*/"
  beginCaptures:
    "0":
      name: "string.quoted.template.ts"
  end:"`"
  endCaptures:
    "0":
      name: "string.quoted.template.ts"
  patterns: [
    {
      include: "source.css"
    }
  ]

update:

Found a solution:

  "template-html":
    name: "meta.template.html.ts"
    begin: "(?<=template\\:)\\s*`"
    beginCaptures:
    "0":
      name: "string.quoted.template.ts"
  end:"`"
  endCaptures:
    "0":
      name: "string.quoted.template.ts"
  patterns: [
    {
      include: "text.html.basic"
    }
  ]
"template-css":
  name: "meta.template.css.ts"
  begin: "(?<=styles\\:)\\s*(\\[)\\s*(`)"
  beginCaptures:
    "2":
      name: "string.quoted.template.ts"
  end:"`"
  endCaptures:
    "0":
      name: "string.quoted.template.ts"
  patterns: [
    {
      include: "source.css"
    }
  ]

Here is the updated screenshot:

enter image description here

like image 68
amin Avatar answered Nov 17 '22 14:11

amin