|
| 1 | +%YAML 1.2 |
| 2 | +--- |
| 3 | +# https://github.com/hyperflask/jinjapy |
| 4 | +# https://github.com/hyperflask/jinja-super-macros |
| 5 | +# https://hyperflask.dev/guides/components/ |
| 6 | +name: HTML (Hyperflask) |
| 7 | +scope: text.html.hyperflask |
| 8 | +version: 2 |
| 9 | + |
| 10 | +extends: Packages/Jinja2/Syntaxes/HTML/HTML (Jinja).sublime-syntax |
| 11 | + |
| 12 | +file_extensions: |
| 13 | + - jpy |
| 14 | + |
| 15 | +variables: |
| 16 | + # Jinja Super Macros |
| 17 | + super_macro_ident: (?:{{super_macro_ident_start}}{{super_macro_ident_part}}*) |
| 18 | + super_macro_ident_start: '[a-zA-Z_]' |
| 19 | + super_macro_ident_part: '[a-zA-Z0-9_-]*' |
| 20 | + |
| 21 | +contexts: |
| 22 | + |
| 23 | +###[ CUSTOM HTML ]############################################################ |
| 24 | + |
| 25 | + main: |
| 26 | + - meta_include_prototype: false |
| 27 | + - meta_scope: text.html.hyperflask meta.template.hyperflask |
| 28 | + - match: '' |
| 29 | + push: [html, frontmatter] |
| 30 | + |
| 31 | + script-type-decider: |
| 32 | + - meta_prepend: true |
| 33 | + - match: (?=(?i:text/hyperscript{{unquoted_attribute_break}}|'text/hyperscript'|"text/hyperscript")) |
| 34 | + set: |
| 35 | + - script-hyperscript |
| 36 | + - tag-generic-attribute-meta |
| 37 | + - tag-generic-attribute-value |
| 38 | + |
| 39 | + tag-other: |
| 40 | + - meta_prepend: true |
| 41 | + - include: jinja-super-macros |
| 42 | + |
| 43 | + tag-attributes: |
| 44 | + - meta_prepend: true |
| 45 | + - include: tag-alpinejs-attributes |
| 46 | + - include: tag-hyperscript-attribute |
| 47 | + |
| 48 | + merge-conflict-markers: |
| 49 | + # required until ST4199 |
| 50 | + - meta_prepend: true |
| 51 | + |
| 52 | +###[ JINJAPY FRONTMATTER ]#################################################### |
| 53 | + |
| 54 | + frontmatter: |
| 55 | + # https://github.com/hyperflask/jinjapy |
| 56 | + - meta_include_prototype: false |
| 57 | + # allow leading whitespace for proper highlighting in fenced code blocks |
| 58 | + - match: \s*(---)\s*\n |
| 59 | + captures: |
| 60 | + 0: meta.frontmatter.jinjapy |
| 61 | + 1: punctuation.section.frontmatter.begin.jinjapy |
| 62 | + 2: constant.other.language-name.jinjapy |
| 63 | + embed: scope:source.python |
| 64 | + embed_scope: meta.frontmatter.jinjapy source.python.embedded.jinjapy |
| 65 | + escape: ^\s*(---)\s*$\n? |
| 66 | + escape_captures: |
| 67 | + 0: meta.frontmatter.jinjapy |
| 68 | + 1: punctuation.section.frontmatter.end.jinjapy |
| 69 | + pop: 1 |
| 70 | + # Ensure to highlight frontmatter if the syntax is embedded, but pop as early as possible |
| 71 | + - match: ^|(?=\S) |
| 72 | + pop: 1 |
| 73 | + |
| 74 | +###[ JINJA SUPER MACROS ]###################################################### |
| 75 | + |
| 76 | + jinja-super-macros: |
| 77 | + # https://github.com/hyperflask/jinja-super-macros |
| 78 | + - match: (</?{)({{super_macro_ident}}) |
| 79 | + captures: |
| 80 | + 1: punctuation.definition.tag.begin.jinja |
| 81 | + 2: entity.name.tag.component.super-macro.jinja |
| 82 | + push: jinja-super-macro-content |
| 83 | + |
| 84 | + jinja-super-macro-content: |
| 85 | + - meta_include_prototype: false |
| 86 | + - meta_scope: meta.tag.component.super-macro.jinja |
| 87 | + - match: \}/?> |
| 88 | + scope: punctuation.definition.tag.end.jinja |
| 89 | + pop: 1 |
| 90 | + - include: merge-conflict-markers |
| 91 | + - match: '{{super_macro_ident}}(?=\s*=)' |
| 92 | + scope: variable.parameter.jinja |
| 93 | + - include: Text (Jinja).sublime-syntax#expressions |
| 94 | + |
| 95 | +###[ ALPINEJS ATTRIBUTES ]#################################################### |
| 96 | + |
| 97 | + tag-alpinejs-attributes: |
| 98 | + # :attr = shorthand syntax for x-bind:attribute="..." |
| 99 | + # @event = shorthand syntax for x-on:event="..." |
| 100 | + - match: '[:@]|(?=x-)' |
| 101 | + scope: entity.other.attribute-name.alpinejs.html punctuation.definition.attribute.alpinejs.html |
| 102 | + push: |
| 103 | + - tag-alpinejs-attribute-meta |
| 104 | + - tag-event-attribute-assignment |
| 105 | + - tag-alpinejs-attribute-name |
| 106 | + |
| 107 | + tag-alpinejs-attribute-meta: |
| 108 | + - meta_include_prototype: false |
| 109 | + - meta_scope: meta.directive.other.alpinejs |
| 110 | + - include: immediately-pop |
| 111 | + |
| 112 | + tag-alpinejs-attribute-name: |
| 113 | + - meta_content_scope: entity.other.attribute-name.alpinejs.html |
| 114 | + - include: tag-alpinejs-attribute-modifier |
| 115 | + - match: ':' |
| 116 | + scope: punctuation.definition.attribute.alpinejs.html |
| 117 | + - match: '["''`<]' |
| 118 | + scope: invalid.illegal.attribute-name.alpinejs.html |
| 119 | + |
| 120 | + tag-alpinejs-attribute-modifier: |
| 121 | + - meta_content_scope: entity.other.attribute-name.alpinejs.html storage.modifier.alpinejs |
| 122 | + - match: '{{attribute_name_break}}' |
| 123 | + pop: 1 |
| 124 | + - match: \. |
| 125 | + scope: entity.other.attribute-name.alpinejs.html punctuation.separator.key-value.alpinejs |
| 126 | + set: tag-alpinejs-attribute-modifier |
| 127 | + |
| 128 | +###[ HYPERSCRIPT TAGS ]####################################################### |
| 129 | + |
| 130 | + script-hyperscript: |
| 131 | + # Vendored from Hyperscript package |
| 132 | + - meta_scope: meta.tag.script.begin.html |
| 133 | + - match: '>' |
| 134 | + scope: punctuation.definition.tag.end.html |
| 135 | + set: script-hyperscript-content |
| 136 | + - include: script-common |
| 137 | + |
| 138 | + script-hyperscript-content: |
| 139 | + - meta_include_prototype: false |
| 140 | + - match: \s*((<!\[)(CDATA)(\[)) |
| 141 | + captures: |
| 142 | + 1: meta.tag.sgml.cdata.html |
| 143 | + 2: punctuation.definition.tag.begin.html |
| 144 | + 3: keyword.declaration.cdata.html |
| 145 | + 4: punctuation.definition.tag.begin.html |
| 146 | + pop: 1 # make sure to match only once |
| 147 | + embed: scope:source.hyperscript |
| 148 | + embed_scope: meta.tag.sgml.cdata.html source.hyperscript.embedded.html |
| 149 | + escape: \]\]> |
| 150 | + escape_captures: |
| 151 | + 0: meta.tag.sgml.cdata.html punctuation.definition.tag.end.html |
| 152 | + - match: '{{script_content_begin}}' |
| 153 | + captures: |
| 154 | + 1: comment.block.html punctuation.definition.comment.begin.html |
| 155 | + pop: 1 # make sure to match only once |
| 156 | + embed: scope:source.hyperscript |
| 157 | + embed_scope: source.hyperscript.embedded.html |
| 158 | + escape: '{{script_content_end}}' |
| 159 | + escape_captures: |
| 160 | + 1: source.hyperscript.embedded.html |
| 161 | + 2: comment.block.html punctuation.definition.comment.end.html |
| 162 | + 3: source.hyperscript.embedded.html |
| 163 | + 4: comment.block.html punctuation.definition.comment.end.html |
| 164 | + |
| 165 | +###[ HYPERSCRIPT ATTRIBUTES ]####################################################### |
| 166 | + |
| 167 | + tag-hyperscript-attribute: |
| 168 | + # Vendored from Hyperscript package |
| 169 | + - match: (?i:_|hs|data-hs){{attribute_name_break}} |
| 170 | + scope: entity.other.attribute-name.hyperscript.html |
| 171 | + push: |
| 172 | + - tag-hyperscript-attribute-meta |
| 173 | + - tag-hyperscript-attribute-assignment |
| 174 | + |
| 175 | + tag-hyperscript-attribute-meta: |
| 176 | + - meta_include_prototype: false |
| 177 | + - meta_scope: meta.attribute-with-value.hyperscript.html |
| 178 | + - include: immediately-pop |
| 179 | + |
| 180 | + tag-hyperscript-attribute-assignment: |
| 181 | + - match: = |
| 182 | + scope: punctuation.separator.key-value.html |
| 183 | + set: |
| 184 | + - immediately-pop |
| 185 | + - tag-hyperscript-attribute-value |
| 186 | + - include: else-pop |
| 187 | + |
| 188 | + tag-hyperscript-attribute-value: |
| 189 | + - match: \" |
| 190 | + scope: meta.string.html string.quoted.double.html punctuation.definition.string.begin.html |
| 191 | + embed: scope:source.hyperscript |
| 192 | + embed_scope: meta.string.html meta.interpolation.html source.hyperscript.embedded.html |
| 193 | + escape: \" |
| 194 | + escape_captures: |
| 195 | + 0: meta.string.html string.quoted.double.html punctuation.definition.string.end.html |
| 196 | + pop: 1 |
| 197 | + - match: \' |
| 198 | + scope: meta.string.html string.quoted.single.html punctuation.definition.string.begin.html |
| 199 | + embed: scope:source.hyperscript |
| 200 | + embed_scope: meta.string.html meta.interpolation.html source.hyperscript.embedded.html |
| 201 | + escape: \' |
| 202 | + escape_captures: |
| 203 | + 0: meta.string.html string.quoted.single.html punctuation.definition.string.end.html |
| 204 | + pop: 1 |
| 205 | + - include: else-pop |
0 commit comments