Skip to content

Commit 8b91aa6

Browse files
jaysoopetebacondarwin
authored andcommitted
docs(directives): fix code lang matching
Closes angular#7339
1 parent 1c0241e commit 8b91aa6

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

docs/app/src/directives.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ angular.module('directives', [])
2222
terminal: true,
2323
compile: function(element) {
2424
var linenums = element.hasClass('linenum');// || element.parent()[0].nodeName === 'PRE';
25-
var match = /lang-(\S)+/.exec(element.className);
25+
var match = /lang-(\S+)/.exec(element[0].className);
2626
var lang = match && match[1];
2727
var html = element.html();
2828
element.html(window.prettyPrintOne(html, lang, linenums));

docs/app/test/directivesSpec.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
describe("code", function() {
2+
var prettyPrintOne, oldPP;
3+
var compile, scope;
4+
5+
var any = jasmine.any;
6+
7+
beforeEach(module('directives'));
8+
9+
beforeEach(inject(function($rootScope, $compile) {
10+
// Provide stub for pretty print function
11+
oldPP = window.prettyPrintOne;
12+
prettyPrintOne = window.prettyPrintOne = jasmine.createSpy();
13+
14+
scope = $rootScope.$new();
15+
compile = $compile;
16+
}));
17+
18+
afterEach(function() {
19+
window.prettyPrintOne = oldPP;
20+
});
21+
22+
23+
it('should pretty print innerHTML', function() {
24+
compile('<code>var x;</code>')(scope);
25+
expect(prettyPrintOne).toHaveBeenCalledWith('var x;', null, false);
26+
});
27+
28+
it('should allow language declaration', function() {
29+
compile('<code class="lang-javascript"></code>')(scope);
30+
expect(prettyPrintOne).toHaveBeenCalledWith(any(String), 'javascript', false);
31+
});
32+
33+
it('supports allow line numbers', function() {
34+
compile('<code class="linenum"></code>')(scope);
35+
expect(prettyPrintOne).toHaveBeenCalledWith(any(String), null, true);
36+
});
37+
});
38+

0 commit comments

Comments
 (0)