Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- also adds multi-match support to endScope
- Loading branch information
1 parent
00c54bd
commit d4bc4ec
Showing
5 changed files
with
200 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
const hljs = require('../../build'); | ||
hljs.debugMode(); | ||
|
||
describe('beginScope and endScope', () => { | ||
before(() => { | ||
const grammar = function() { | ||
return { | ||
contains: [ | ||
{ | ||
begin: /xyz/, | ||
end: /123/, | ||
scope: "string", | ||
beginScope: "red", | ||
endScope: "green" | ||
}, | ||
{ | ||
begin: /123/, | ||
end: [ /a/,/((b))/,/c/,/d/ ], | ||
endScope: { 1: "apple", 2: "boy", 4: "delta" } | ||
}, | ||
{ | ||
begin: /dumb/, | ||
end: /luck/, | ||
beginScope: "red", | ||
endScope: "green" | ||
}, | ||
{ | ||
begin: /abc/, | ||
beginScope: "letters", | ||
contains: [ | ||
{ match: /def/, scope: "more" } | ||
] | ||
} | ||
] | ||
} | ||
}; | ||
hljs.registerLanguage("test", grammar); | ||
}); | ||
after(() => { | ||
hljs.unregisterLanguage("test"); | ||
}); | ||
it('should support multi-class', () => { | ||
const code = "123 abcd"; | ||
const result = hljs.highlight(code, { language: 'test' }); | ||
|
||
result.value.should.equal(`123 <span class="hljs-apple">a</span><span class="hljs-boy">b</span>c<span class="hljs-delta">d</span>`); | ||
}) | ||
it('should support an outer scope wrapper', () => { | ||
const code = "xyz me 123"; | ||
const result = hljs.highlight(code, { language: 'test' }); | ||
|
||
result.value.should.equal( | ||
`<span class="hljs-string">` + | ||
`<span class="hljs-red">xyz</span> me <span class="hljs-green">123</span>` + | ||
`</span>`); | ||
}) | ||
it('should support textual beginScope & endScope pair', () => { | ||
const code = "dumb really luck"; | ||
const result = hljs.highlight(code, { language: 'test' }); | ||
|
||
result.value.should.equal(`<span class="hljs-red">dumb</span> really <span class="hljs-green">luck</span>`); | ||
}); | ||
it('should support textual beginScope', () => { | ||
const code = "abcdef"; | ||
const result = hljs.highlight(code, { language: 'test' }); | ||
|
||
result.value.should.equal(`<span class="hljs-letters">abc</span><span class="hljs-more">def</span>`); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters