Skip to content

Commit

Permalink
Relax highlighting rules on HTML element names
Browse files Browse the repository at this point in the history
Instead of requiring a name to match an existing HTML element, this relaxes the
restrictions to:

- starting with [a-zA-Z] (matching the HTML parser WICG/webcomponents#239 (comment))
- then continuing with anything other than a space, forward slash or closing
  angle bracket

This is similar to the fix to the following issue in the HTML syntax
highlighting repo (and actually depends on the "derivative" syntax that was
created for that issue):

textmate/html.tmbundle#92
  • Loading branch information
karlhorky committed Aug 18, 2019
1 parent 58a06b3 commit d64818b
Show file tree
Hide file tree
Showing 5 changed files with 386 additions and 38 deletions.
18 changes: 9 additions & 9 deletions markdown.tmLanguage.base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,23 @@ repository:
- begin: (?i)(^|\G)\s*(?=<(script|style|pre)(\s|$|>)(?!.*?</(script|style|pre)>))
end: (?i)(.*)((</)(script|style|pre)(>))
endCaptures:
'1': { patterns: [ {include: text.html.basic} ]}
'1': { patterns: [ {include: text.html.derivative} ]}
'2': {name: meta.tag.structure.$4.end.html}
'3': {name: punctuation.definition.tag.begin.html}
'4': {name: entity.name.tag.html}
'5': {name: punctuation.definition.tag.end.html}
patterns:
- begin: (\s*|$)
patterns:
- {include: text.html.basic}
- {include: text.html.derivative}
while: (?i)^(?!.*</(script|style|pre)>)
- begin: (?i)(^|\G)\s*(?=</?(address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(\s|$|/?>))
- begin: (?i)(^|\G)\s*(?=</?[a-zA-Z]+[^\s/&gt;]*(\s|$|/?>))
patterns:
- {include: text.html.basic}
- {include: text.html.derivative}
while: ^(?!\s*$)
- begin: (^|\G)\s*(?=(<[a-zA-Z0-9\-](/?>|\s.*?>)|</[a-zA-Z0-9\-]>)\s*$)
patterns:
- {include: text.html.basic}
- {include: text.html.derivative}
while: ^(?!\s*$)
link-def:
captures:
Expand Down Expand Up @@ -149,7 +149,7 @@ repository:
name: meta.paragraph.markdown
patterns:
- {include: '#inline'}
- {include: text.html.basic}
- {include: text.html.derivative}
- {include: '#heading-setext'}
while: (^|\G)(?!\s*$|#|[ ]{0,3}([-*_>][ ]{2,}){3,}[ \t]*$\n?|[ ]{0,3}[*+->]|[
]{0,3}[0-9]+\.)
Expand Down Expand Up @@ -177,7 +177,7 @@ repository:
name: meta.paragraph.markdown
patterns:
- {include: '#inline'}
- {include: text.html.basic}
- {include: text.html.derivative}
- {include: '#heading-setext'}
while: (^|\G)((?=\s*[-=]{3,}\s*$)|[ ]{4,}(?=\S))
raw_block: {begin: '(^|\G)([ ]{4}|\t)', name: markup.raw.block.markdown, while: '(^|\G)([
Expand Down Expand Up @@ -260,7 +260,7 @@ repository:
begin: (?=<[^>]*?>)
end: (?<=>)
patterns:
- {include: text.html.basic}
- {include: text.html.derivative}
- {include: '#escape'}
- {include: '#ampersand'}
- {include: '#bracket'}
Expand Down Expand Up @@ -372,7 +372,7 @@ repository:
begin: (?=<[^>]*?>)
end: (?<=>)
patterns:
- {include: text.html.basic}
- {include: text.html.derivative}
- {include: '#escape'}
- {include: '#ampersand'}
- {include: '#bracket'}
Expand Down
22 changes: 11 additions & 11 deletions syntaxes/markdown.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
<array>
<dict>
<key>include</key>
<string>text.html.basic</string>
<string>text.html.derivative</string>
</dict>
</array>
</dict>
Expand Down Expand Up @@ -616,7 +616,7 @@
<array>
<dict>
<key>include</key>
<string>text.html.basic</string>
<string>text.html.derivative</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -3152,7 +3152,7 @@
<array>
<dict>
<key>include</key>
<string>text.html.basic</string>
<string>text.html.derivative</string>
</dict>
</array>
</dict>
Expand Down Expand Up @@ -3186,7 +3186,7 @@
<array>
<dict>
<key>include</key>
<string>text.html.basic</string>
<string>text.html.derivative</string>
</dict>
</array>
<key>while</key>
Expand All @@ -3196,12 +3196,12 @@
</dict>
<dict>
<key>begin</key>
<string>(?i)(^|\G)\s*(?=&lt;/?(address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(\s|$|/?&gt;))</string>
<string>(?i)(^|\G)\s*(?=&lt;/?[a-zA-Z]+[^\s/&gt;]*(\s|$|/?&gt;))</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>text.html.basic</string>
<string>text.html.derivative</string>
</dict>
</array>
<key>while</key>
Expand All @@ -3214,7 +3214,7 @@
<array>
<dict>
<key>include</key>
<string>text.html.basic</string>
<string>text.html.derivative</string>
</dict>
</array>
<key>while</key>
Expand Down Expand Up @@ -3323,7 +3323,7 @@
</dict>
<dict>
<key>include</key>
<string>text.html.basic</string>
<string>text.html.derivative</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -3409,7 +3409,7 @@
</dict>
<dict>
<key>include</key>
<string>text.html.basic</string>
<string>text.html.derivative</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -3589,7 +3589,7 @@
<array>
<dict>
<key>include</key>
<string>text.html.basic</string>
<string>text.html.derivative</string>
</dict>
</array>
</dict>
Expand Down Expand Up @@ -3868,7 +3868,7 @@
<array>
<dict>
<key>include</key>
<string>text.html.basic</string>
<string>text.html.derivative</string>
</dict>
</array>
</dict>
Expand Down
5 changes: 5 additions & 0 deletions test/colorize-fixtures/issue-53.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<StackLayout orientation="vertical">PascalCase</StackLayout>

<WelcomeMessage greetingText="hi" />

text <RainbowAnimate>PascalCase</RainbowAnimate> text
36 changes: 18 additions & 18 deletions test/colorize-results/issue-42_md.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@
},
{
"c": "Sequence",
"t": "text.html.markdown markup.fenced_code.block.markdown",
"t": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.swift meta.definition.function.swift meta.generic-parameter-clause.swift meta.generic-parameter-constraint.swift entity.other.inherited-class.swift meta.type-name.swift support.type.swift",
"r": {
"dark_plus": "default: #D4D4D4",
"light_plus": "default: #000000",
"dark_vs": "default: #D4D4D4",
"light_vs": "default: #000000",
"hc_black": "default: #FFFFFF"
"dark_plus": "support.type: #4EC9B0",
"light_plus": "support.type: #267F99",
"dark_vs": "meta.embedded: #D4D4D4",
"light_vs": "meta.embedded: #000000",
"hc_black": "support.type: #4EC9B0"
}
},
{
Expand Down Expand Up @@ -617,13 +617,13 @@
},
{
"c": "=",
"t": "text.html.markdown markup.fenced_code.block.markdown",
"t": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.swift keyword.operator.custom.infix.swift",
"r": {
"dark_plus": "default: #D4D4D4",
"light_plus": "default: #000000",
"dark_vs": "default: #D4D4D4",
"light_vs": "default: #000000",
"hc_black": "default: #FFFFFF"
"dark_plus": "keyword.operator: #D4D4D4",
"light_plus": "keyword.operator: #000000",
"dark_vs": "keyword.operator: #D4D4D4",
"light_vs": "keyword.operator: #000000",
"hc_black": "keyword.operator: #D4D4D4"
}
},
{
Expand Down Expand Up @@ -826,13 +826,13 @@
},
{
"c": "+=",
"t": "text.html.markdown markup.fenced_code.block.markdown",
"t": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.swift keyword.operator.custom.infix.swift",
"r": {
"dark_plus": "default: #D4D4D4",
"light_plus": "default: #000000",
"dark_vs": "default: #D4D4D4",
"light_vs": "default: #000000",
"hc_black": "default: #FFFFFF"
"dark_plus": "keyword.operator: #D4D4D4",
"light_plus": "keyword.operator: #000000",
"dark_vs": "keyword.operator: #D4D4D4",
"light_vs": "keyword.operator: #000000",
"hc_black": "keyword.operator: #D4D4D4"
}
},
{
Expand Down
Loading

0 comments on commit d64818b

Please sign in to comment.