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

Fix HTML snippets #175

Merged
merged 5 commits into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
23 changes: 20 additions & 3 deletions snippets/language-html.cson
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
'.text.html - .punctuation.tag.begin':
# Important: When adding a new snippet,
# there is a second section halfway down this file
# where you need to null-out the snippet to prevent it from
# appearing in tags or embedded contexts
'.text.html':
# A
'Anchor':
'prefix': 'a'
Expand Down Expand Up @@ -386,7 +390,6 @@
'prefix': 'wbr'
'body': '<wbr>'


# These null out the snippets so the snippets are not available when in a tag or
# in embedded contexts like <script> and <style>
'.text.html .meta.tag, .text.html .embedded':
Expand Down Expand Up @@ -466,6 +469,8 @@
'Embed':
'prefix': 'embed'
# F
'Favicon':
'prefix': 'favicon'
'Fieldset':
'prefix': 'fieldset'
'Figure Caption':
Expand Down Expand Up @@ -494,6 +499,8 @@
'prefix': 'head'
'Header':
'prefix': 'header'
'Heading Group':
'prefix': 'hgroup'
'Horizontal Rule':
'prefix': 'hr'
'HTML':
Expand All @@ -507,6 +514,8 @@
'prefix': 'input'
'Image':
'prefix': 'img'
'Import':
'prefix': 'import'
'Inserted Text':
'prefix': 'ins'
# J
Expand All @@ -531,6 +540,8 @@
'prefix': 'map'
'Mark':
'prefix': 'mark'
'MathML':
'prefix': 'math'
'Menu':
'prefix': 'menu'
'Menu Item':
Expand All @@ -554,7 +565,7 @@
'Option Group':
'prefix': 'optgroup'
'Option':
'prefix': 'opt'
'prefix': 'option'
'Output':
'prefix': 'output'
# P
Expand All @@ -570,10 +581,14 @@
'Quote':
'prefix': 'q'
# R
'Ruby Base':
'prefix': 'rb'
'Ruby Parenthesis':
'prefix': 'rp'
'Ruby Pronunciation':
'prefix': 'rt'
'Ruby Text Container':
'prefix': 'rtc'
'Ruby Annotation':
'prefix': 'ruby'
# S
Expand Down Expand Up @@ -605,6 +620,8 @@
'prefix': 'summary'
'Superscript':
'prefix': 'sup'
'SVG':
'prefix': 'svg'
# T
'Table':
'prefix': 'table'
Expand Down
23 changes: 23 additions & 0 deletions spec/html-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,26 @@ describe 'HTML grammar', ->
it "tolerates hyphens in other tag names", ->
lines = grammar.tokenizeLines '<foo-bar>'
expect(lines[0][1]).toEqual value: 'foo-bar', scopes: ['text.html.basic', 'meta.tag.other.html', 'entity.name.tag.other.html']

describe "snippets", ->
snippetsModule = null

beforeEach ->
# FIXME: This should just be atom.packages.loadPackage('snippets'),
# but a bug in PackageManager::resolvePackagePath where it finds language-html's
# `snippets` directory before the actual package necessitates passing an absolute path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you feel about including a link to the issue here? That way, future devs will have an easy way to find out whether the issue has been resolved, and that will let them know whether they can change the code to use atom.packages.loadPackage('snippets').

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That reminds me - I still need to file an issue for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! See the line below.

snippetsPath = path.join(atom.packages.resourcePath, 'node_modules', 'snippets')
snippetsModule = require(atom.packages.loadPackage(snippetsPath).getMainModulePath())

# Disable loading of user snippets before the package is activated
spyOn(snippetsModule, 'loadUserSnippets').andCallFake (callback) -> callback({})

snippetsModule.activate()

waitsFor 'snippets to load', (done) -> snippetsModule.onDidLoadSnippets(done)

it "suggests snippets", ->
expect(Object.keys(snippetsModule.parsedSnippetsForScopes(['.text.html'])).length).toBeGreaterThan 10

it "does not suggest any HTML snippets when in embedded scripts", ->
expect(Object.keys(snippetsModule.parsedSnippetsForScopes(['.text.html .source.js.embedded.html'])).length).toBe 0