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

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #49 from atom/as-use-shadow-dom-prefixes
Adopt the new `syntax--` convention when transforming scopes into class names
  • Loading branch information
Antonio Scandurra committed Jan 20, 2017
2 parents e6ed916 + 97a46e8 commit 77e03c4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.coffee
Expand Up @@ -36,6 +36,6 @@ module.exports = (grunt) ->
grunt.file.delete('gen') if grunt.file.exists('gen')

grunt.registerTask('lint', ['coffeelint'])
grunt.registerTask('default', ['coffeelint', 'coffee'])
grunt.registerTask('default', ['coffeelint', 'coffee', 'build-grammars'])
grunt.registerTask('test', ['default', 'lint', 'shell:test'])
grunt.registerTask('prepublish', ['clean', 'build-grammars', 'test'])
28 changes: 14 additions & 14 deletions spec/highlights-spec.coffee
Expand Up @@ -6,33 +6,33 @@ describe "Highlights", ->
it "includes the grammar when the path is a file", ->
highlights = new Highlights(includePath: path.join(__dirname, 'fixtures', 'includes'))
html = highlights.highlightSync(fileContents: 'test', scopeName: 'include1')
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="include1"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--include1"><span>test</span></span></div></pre>'

it "includes the grammars when the path is a directory", ->
highlights = new Highlights(includePath: path.join(__dirname, 'fixtures', 'includes', 'include1.cson'))
html = highlights.highlightSync(fileContents: 'test', scopeName: 'include1')
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="include1"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--include1"><span>test</span></span></div></pre>'

it "overrides built-in grammars", ->
highlights = new Highlights(includePath: path.join(__dirname, 'fixtures', 'includes'))
html = highlights.highlightSync(fileContents: 's = "test"', scopeName: 'source.coffee')
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="source coffee"><span>s&nbsp;=&nbsp;&quot;test&quot;</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--source syntax--coffee"><span>s&nbsp;=&nbsp;&quot;test&quot;</span></span></div></pre>'

describe "highlightSync", ->
it "returns an HTML string", ->
highlights = new Highlights()
html = highlights.highlightSync(fileContents: 'test')
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="text plain null-grammar"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--text syntax--plain syntax--null-grammar"><span>test</span></span></div></pre>'

it "uses the given scope name as the grammar to tokenize with", ->
highlights = new Highlights()
html = highlights.highlightSync(fileContents: 'test', scopeName: 'source.coffee')
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="source coffee"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--source syntax--coffee"><span>test</span></span></div></pre>'

it "uses the best grammar match when no scope name is specified", ->
highlights = new Highlights()
html = highlights.highlightSync(fileContents: 'test', filePath: 'test.coffee')
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="source coffee"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--source syntax--coffee"><span>test</span></span></div></pre>'

describe "requireGrammarsSync", ->
it "loads the grammars from a file-based npm module path", ->
Expand All @@ -49,7 +49,7 @@ describe "Highlights", ->
highlights = new Highlights()
highlights.requireGrammarsSync(modulePath: require.resolve('language-erlang/package.json'))
html = highlights.highlightSync(fileContents: 'test', scopeName: 'source.coffee')
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="source coffee"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--source syntax--coffee"><span>test</span></span></div></pre>'

#
# async tests
Expand All @@ -60,22 +60,22 @@ describe "Highlights", ->
highlights = new Highlights(includePath: path.join(__dirname, 'fixtures', 'includes'))
highlights.highlight(fileContents: 'test', scopeName: 'include1', (err, html) ->
expect(not err).toBe true
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="include1"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--include1"><span>test</span></span></div></pre>'
done()
)

it "includes the grammars when the path is a directory", (done) ->
highlights = new Highlights(includePath: path.join(__dirname, 'fixtures', 'includes', 'include1.cson'))
highlights.highlight fileContents: 'test', scopeName: 'include1', (err, html) ->
expect(not err).toBe true
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="include1"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--include1"><span>test</span></span></div></pre>'
done()

it "overrides built-in grammars", (done) ->
highlights = new Highlights(includePath: path.join(__dirname, 'fixtures', 'includes'))
highlights.highlight(fileContents: 's = "test"', scopeName: 'source.coffee', (err, html) ->
expect(not err).toBe true
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="source coffee"><span>s&nbsp;=&nbsp;&quot;test&quot;</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--source syntax--coffee"><span>s&nbsp;=&nbsp;&quot;test&quot;</span></span></div></pre>'
done()
)

Expand All @@ -84,20 +84,20 @@ describe "Highlights", ->
highlights = new Highlights()
highlights.highlight fileContents: 'test', (err, html) ->
expect(not err).toBe true
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="text plain null-grammar"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--text syntax--plain syntax--null-grammar"><span>test</span></span></div></pre>'
done()

it "uses the given scope name as the grammar to tokenize with", (done) ->
highlights = new Highlights()
highlights.highlight fileContents: 'test', scopeName: 'source.coffee', (err, html) ->
expect(not err).toBe true
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="source coffee"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--source syntax--coffee"><span>test</span></span></div></pre>'
done()

it "uses the best grammar match when no scope name is specified", (done) ->
highlights = new Highlights()
highlights.highlight fileContents: 'test', filePath: 'test.coffee', (err, html) ->
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="source coffee"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--source syntax--coffee"><span>test</span></span></div></pre>'
done()

describe "async: requireGrammars", ->
Expand All @@ -120,5 +120,5 @@ describe "Highlights", ->
highlights.requireGrammars modulePath: require.resolve('language-erlang/package.json'), (err, html) ->
highlights.highlight fileContents: 'test', scopeName: 'source.coffee', (err, html) ->
expect(not err).toBe true
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="source coffee"><span>test</span></span></div></pre>'
expect(html).toBe '<pre class="editor editor-colors"><div class="line"><span class="syntax--source syntax--coffee"><span>test</span></span></div></pre>'
done()
5 changes: 4 additions & 1 deletion src/highlights.coffee
Expand Up @@ -299,7 +299,10 @@ class Highlights

pushScope: (scopeStack, scope, html) ->
scopeStack.push(scope)
html += "<span class=\"#{scope.replace(/\.+/g, ' ')}\">"
if scope
html += "<span class=\"syntax--#{scope.replace(/\.+/g, ' syntax--')}\">"
else
html += "<span>"

popScope: (scopeStack, html) ->
scopeStack.pop()
Expand Down

0 comments on commit 77e03c4

Please sign in to comment.