Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Allow for unrecognized tags to be self-closing #178

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions grammars/html.cson
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,16 @@
]
}
{
'begin': '(</?)([a-zA-Z0-9:-]+)'
# Opening tag (optionally self-closing)
'begin': '(<)([a-zA-Z0-9:-]+)'
'beginCaptures':
'1':
'name': 'punctuation.definition.tag.begin.html'
'2':
'name': 'entity.name.tag.other.html'
'end': '(>)'
'end': '/?>'
'endCaptures':
'1':
'0':
'name': 'punctuation.definition.tag.end.html'
'name': 'meta.tag.other.html'
'patterns': [
Expand All @@ -373,6 +374,20 @@
}
]
}
{
# Closing tag, which doesn't allow attributes
'begin': '(</)([a-zA-Z0-9:-]+)'
'beginCaptures':
'1':
'name': 'punctuation.definition.tag.begin.html'
'2':
'name': 'entity.name.tag.other.html'
'end': '>'
'endCaptures':
'0':
'name': 'punctuation.definition.tag.end.html'
'name': 'meta.tag.other.html'
}
{
'include': '#text-entities'
}
Expand Down
26 changes: 26 additions & 0 deletions spec/html-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,32 @@ describe 'HTML grammar', ->
expect(tokens[1]).toEqual value: 'foo', scopes: ['text.html.basic', 'meta.tag.other.html', 'entity.name.tag.other.html']
expect(tokens[2]).toEqual value: '>', scopes: ['text.html.basic', 'meta.tag.other.html', 'punctuation.definition.tag.end.html']

it 'tokenizes unrecognized self-closing tags', ->
{tokens} = grammar.tokenizeLine '<foo/>'
expect(tokens[0]).toEqual value: '<', scopes: ['text.html.basic', 'meta.tag.other.html', 'punctuation.definition.tag.begin.html']
expect(tokens[1]).toEqual value: 'foo', scopes: ['text.html.basic', 'meta.tag.other.html', 'entity.name.tag.other.html']
expect(tokens[2]).toEqual value: '/>', scopes: ['text.html.basic', 'meta.tag.other.html', 'punctuation.definition.tag.end.html']

it 'tokenizes attributes in opening tags of unrecognized tag names', ->
{tokens} = grammar.tokenizeLine '<foo class="test">'
expect(tokens[0]).toEqual value: '<', scopes: ['text.html.basic', 'meta.tag.other.html', 'punctuation.definition.tag.begin.html']
expect(tokens[1]).toEqual value: 'foo', scopes: ['text.html.basic', 'meta.tag.other.html', 'entity.name.tag.other.html']
expect(tokens[3]).toEqual value: 'class', scopes: ['text.html.basic', 'meta.tag.other.html', 'meta.attribute-with-value.class.html', 'entity.other.attribute-name.class.html']
expect(tokens[8]).toEqual value: '>', scopes: ['text.html.basic', 'meta.tag.other.html', 'punctuation.definition.tag.end.html']

it 'tokenizes the closing tag of an unrecognized tag name', ->
{tokens} = grammar.tokenizeLine '</foo>'
expect(tokens[0]).toEqual value: '</', scopes: ['text.html.basic', 'meta.tag.other.html', 'punctuation.definition.tag.begin.html']
expect(tokens[1]).toEqual value: 'foo', scopes: ['text.html.basic', 'meta.tag.other.html', 'entity.name.tag.other.html']
expect(tokens[2]).toEqual value: '>', scopes: ['text.html.basic', 'meta.tag.other.html', 'punctuation.definition.tag.end.html']

it 'does not tokenize attributes in closing tags of unrecognized tag names', ->
{tokens} = grammar.tokenizeLine '</foo class="test">'
expect(tokens[0]).toEqual value: '</', scopes: ['text.html.basic', 'meta.tag.other.html', 'punctuation.definition.tag.begin.html']
expect(tokens[1]).toEqual value: 'foo', scopes: ['text.html.basic', 'meta.tag.other.html', 'entity.name.tag.other.html']
expect(tokens[2]).toEqual value: ' class="test"', scopes: ['text.html.basic', 'meta.tag.other.html']
expect(tokens[3]).toEqual value: '>', scopes: ['text.html.basic', 'meta.tag.other.html', 'punctuation.definition.tag.end.html']

it 'tolerates colons in other tag names', ->
{tokens} = grammar.tokenizeLine '<foo:bar>'
expect(tokens[1]).toEqual value: 'foo:bar', scopes: ['text.html.basic', 'meta.tag.other.html', 'entity.name.tag.other.html']
Expand Down