File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ angular.module('directives', [])
22
22
terminal : true ,
23
23
compile : function ( element ) {
24
24
var linenums = element . hasClass ( 'linenum' ) ; // || element.parent()[0].nodeName === 'PRE';
25
- var match = / l a n g - ( \S ) + / . exec ( element . className ) ;
25
+ var match = / l a n g - ( \S + ) / . exec ( element [ 0 ] . className ) ;
26
26
var lang = match && match [ 1 ] ;
27
27
var html = element . html ( ) ;
28
28
element . html ( window . prettyPrintOne ( html , lang , linenums ) ) ;
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments