Skip to content

Commit 52392b3

Browse files
committed
Add HTML (CoffeeScript) syntax definition
Resolves #122
1 parent cfa43ba commit 52392b3

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

HTML (CoffeeScript).sublime-syntax

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
%YAML 1.2
2+
---
3+
# http://www.sublimetext.com/docs/syntax.html
4+
name: HTML (CoffeeScript)
5+
scope: text.html.coffee
6+
version: 2
7+
8+
extends: Packages/HTML/HTML.sublime-syntax
9+
10+
file_extensions:
11+
- coffee.html
12+
13+
contexts:
14+
15+
script-common:
16+
- meta_prepend: true
17+
- match: (?i:lang){{attribute_name_break}}
18+
scope: meta.attribute-with-value.html entity.other.attribute-name.html
19+
set: script-lang-attribute-assignment
20+
21+
script-lang-attribute-assignment:
22+
- meta_content_scope: meta.tag.script.begin.html meta.attribute-with-value.html
23+
- match: =
24+
scope: punctuation.separator.key-value.html
25+
set: script-lang-attribute-value
26+
- match: (?=\S)
27+
set: script-javascript
28+
29+
script-lang-attribute-value:
30+
- meta_include_prototype: false
31+
- meta_scope: meta.tag.script.begin.html meta.attribute-with-value.html
32+
- match: (?=(?i:coffee{{unquoted_attribute_break}}|'coffee'|"coffee"))
33+
set:
34+
- script-coffee
35+
- tag-generic-attribute-meta
36+
- tag-generic-attribute-value
37+
- match: (?=\S)
38+
set:
39+
- script-javascript
40+
- tag-generic-attribute-meta
41+
- tag-generic-attribute-value
42+
43+
script-type-decider:
44+
- meta_prepend: true
45+
- match: (?={{coffee_mime_type}}{{unquoted_attribute_break}}|'{{coffee_mime_type}}'|"{{coffee_mime_type}}")
46+
set:
47+
- script-coffee
48+
- tag-generic-attribute-meta
49+
- tag-generic-attribute-value
50+
51+
script-coffee:
52+
- meta_include_prototype: false
53+
- meta_scope: meta.tag.script.begin.html
54+
- match: '>'
55+
scope: punctuation.definition.tag.end.html
56+
set: script-coffee-content
57+
- include: script-common
58+
59+
script-coffee-content:
60+
- meta_include_prototype: false
61+
- match: \s*((<!\[)(CDATA)(\[))
62+
captures:
63+
1: meta.tag.sgml.cdata.html
64+
2: punctuation.definition.tag.begin.html
65+
3: keyword.declaration.cdata.html
66+
4: punctuation.definition.tag.begin.html
67+
pop: 1 # make sure to match only once
68+
embed: scope:source.coffee
69+
embed_scope: meta.tag.sgml.cdata.html source.coffee.embedded.html
70+
escape: \]\]>
71+
escape_captures:
72+
0: meta.tag.sgml.cdata.html punctuation.definition.tag.end.html
73+
- match: '{{script_content_begin}}'
74+
captures:
75+
1: comment.block.html punctuation.definition.comment.begin.html
76+
pop: 1 # make sure to match only once
77+
embed: scope:source.coffee
78+
embed_scope: source.coffee.embedded.html
79+
escape: '{{script_content_end}}'
80+
escape_captures:
81+
1: source.coffee.embedded.html
82+
2: comment.block.html punctuation.definition.comment.end.html
83+
3: source.coffee.embedded.html
84+
4: comment.block.html punctuation.definition.comment.end.html
85+
86+
variables:
87+
88+
coffee_mime_type: |-
89+
(?xi: (?: (?: application |text ) / coffee(?:script)? ) {{mime_type_parameters}}? )

tests/syntax_test_scope.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SYNTAX TEST "HTML (CoffeeScript).sublime-syntax"
2+
3+
<script type="text/coffeescript">
4+
# <- meta.tag.script.begin.html punctuation.definition.tag.begin.html
5+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.script.begin.html
6+
#^^^^^^ entity.name.tag.script.html
7+
# ^^^^ entity.other.attribute-name.html
8+
# ^ punctuation.separator.key-value.html
9+
# ^^^^^^^^^^^^^^^^^^^ meta.string.html string.quoted.double.html
10+
# ^ punctuation.definition.tag.end.html
11+
class extends parentClass
12+
# <- source.coffee.embedded.html meta.class.coffee storage.type.class.coffee
13+
#^^^^^^^^^^^^^^^^^^^^^^^^ source.coffee.embedded.html meta.class.coffee
14+
#^^^^ storage.type.class.coffee
15+
# ^^^^^^^ keyword.control.inheritance.coffee
16+
# ^^^^^^^^^^^ entity.other.inherited-class.coffee
17+
constructor: ->
18+
return
19+
# <- source.coffee.embedded.html
20+
# ^^^^^^ source.coffee.embedded.html keyword.control.flow.coffee
21+
</script>
22+
# <- meta.tag.script.end.html punctuation.definition.tag.begin.html
23+
#^^^^^^^^ meta.tag.script.end.html
24+
#^ punctuation.definition.tag.begin.html
25+
# ^^^^^^ entity.name.tag.script.html
26+
# ^ punctuation.definition.tag.end.html
27+
28+
<script lang="coffee">
29+
# <- meta.tag.script.begin.html punctuation.definition.tag.begin.html
30+
#^^^^^^^^^^^^^^^^^^^^^ meta.tag.script.begin.html
31+
#^^^^^^ entity.name.tag.script.html
32+
# ^^^^ entity.other.attribute-name.html
33+
# ^ punctuation.separator.key-value.html
34+
# ^^^^^^^^ meta.string.html string.quoted.double.html
35+
# ^ punctuation.definition.tag.end.html
36+
class extends parentClass
37+
# <- source.coffee.embedded.html meta.class.coffee storage.type.class.coffee
38+
#^^^^^^^^^^^^^^^^^^^^^^^^ source.coffee.embedded.html meta.class.coffee
39+
#^^^^ storage.type.class.coffee
40+
# ^^^^^^^ keyword.control.inheritance.coffee
41+
# ^^^^^^^^^^^ entity.other.inherited-class.coffee
42+
constructor: ->
43+
return
44+
# <- source.coffee.embedded.html
45+
# ^^^^^^ source.coffee.embedded.html keyword.control.flow.coffee
46+
</script>
47+
# <- meta.tag.script.end.html punctuation.definition.tag.begin.html
48+
#^^^^^^^^ meta.tag.script.end.html
49+
#^ punctuation.definition.tag.begin.html
50+
# ^^^^^^ entity.name.tag.script.html
51+
# ^ punctuation.definition.tag.end.html

0 commit comments

Comments
 (0)