Skip to content

Commit 4825ce9

Browse files
committed
Merge branch 'feature/fix-63'
2 parents 401d736 + 86277fd commit 4825ce9

6 files changed

+121
-22
lines changed

angular-highlightjs.js

+39-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*! angular-highlightjs
22
version: 0.6.0
3-
build date: 2016-03-20
3+
build date: 2016-04-02
44
author: Chih-Hsuan Fan
55
https://github.com/pc035860/angular-highlightjs.git */
66

@@ -16,6 +16,37 @@ https://github.com/pc035860/angular-highlightjs.git */
1616

1717
/*global angular, hljs*/
1818

19+
/**
20+
* returns a function to transform attrs to supported ones
21+
*
22+
* escape:
23+
* hljs-escape or escape
24+
* no-escape:
25+
* hljs-no-escape or no-escape
26+
* onhighlight:
27+
* hljs-onhighlight or onhighlight
28+
*/
29+
function attrGetter(attrs) {
30+
return function (name) {
31+
switch (name) {
32+
case 'escape':
33+
return angular.isDefined(attrs.hljsEscape) ?
34+
attrs.hljsEscape :
35+
attrs.escape;
36+
37+
case 'no-escape':
38+
return angular.isDefined(attrs.hljsNoEscape) ?
39+
attrs.hljsNoEscape :
40+
attrs.noEscape;
41+
42+
case 'onhighlight':
43+
return angular.isDefined(attrs.hljsOnhighlight) ?
44+
attrs.hljsOnhighlight :
45+
attrs.onhighlight;
46+
}
47+
};
48+
}
49+
1950
function shouldHighlightStatics(attrs) {
2051
var should = true;
2152
angular.forEach([
@@ -273,17 +304,19 @@ hljsDir = /*@ngInject*/ ["$parse", function ($parse) {
273304
return function postLink(scope, iElm, iAttrs, ctrl) {
274305
var escapeCheck;
275306

276-
if (angular.isDefined(iAttrs.escape)) {
277-
escapeCheck = $parse(iAttrs.escape);
278-
} else if (angular.isDefined(iAttrs.noEscape)) {
307+
var attrs = attrGetter(iAttrs);
308+
309+
if (angular.isDefined(attrs('escape'))) {
310+
escapeCheck = $parse(attrs('escape'));
311+
} else if (angular.isDefined(attrs('no-escape'))) {
279312
escapeCheck = $parse('false');
280313
}
281314

282315
ctrl.init(iElm.find('code'));
283316

284-
if (iAttrs.onhighlight) {
317+
if (attrs('onhighlight')) {
285318
ctrl.highlightCallback(function () {
286-
scope.$eval(iAttrs.onhighlight);
319+
scope.$eval(attrs('onhighlight'));
287320
});
288321
}
289322

angular-highlightjs.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/angular-highlightjs.js

+39-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*! angular-highlightjs
22
version: 0.6.0
3-
build date: 2016-03-20
3+
build date: 2016-04-02
44
author: Chih-Hsuan Fan
55
https://github.com/pc035860/angular-highlightjs.git */
66

@@ -16,6 +16,37 @@ https://github.com/pc035860/angular-highlightjs.git */
1616

1717
/*global angular, hljs*/
1818

19+
/**
20+
* returns a function to transform attrs to supported ones
21+
*
22+
* escape:
23+
* hljs-escape or escape
24+
* no-escape:
25+
* hljs-no-escape or no-escape
26+
* onhighlight:
27+
* hljs-onhighlight or onhighlight
28+
*/
29+
function attrGetter(attrs) {
30+
return function (name) {
31+
switch (name) {
32+
case 'escape':
33+
return angular.isDefined(attrs.hljsEscape) ?
34+
attrs.hljsEscape :
35+
attrs.escape;
36+
37+
case 'no-escape':
38+
return angular.isDefined(attrs.hljsNoEscape) ?
39+
attrs.hljsNoEscape :
40+
attrs.noEscape;
41+
42+
case 'onhighlight':
43+
return angular.isDefined(attrs.hljsOnhighlight) ?
44+
attrs.hljsOnhighlight :
45+
attrs.onhighlight;
46+
}
47+
};
48+
}
49+
1950
function shouldHighlightStatics(attrs) {
2051
var should = true;
2152
angular.forEach([
@@ -273,17 +304,19 @@ hljsDir = /*@ngInject*/ ["$parse", function ($parse) {
273304
return function postLink(scope, iElm, iAttrs, ctrl) {
274305
var escapeCheck;
275306

276-
if (angular.isDefined(iAttrs.escape)) {
277-
escapeCheck = $parse(iAttrs.escape);
278-
} else if (angular.isDefined(iAttrs.noEscape)) {
307+
var attrs = attrGetter(iAttrs);
308+
309+
if (angular.isDefined(attrs('escape'))) {
310+
escapeCheck = $parse(attrs('escape'));
311+
} else if (angular.isDefined(attrs('no-escape'))) {
279312
escapeCheck = $parse('false');
280313
}
281314

282315
ctrl.init(iElm.find('code'));
283316

284-
if (iAttrs.onhighlight) {
317+
if (attrs('onhighlight')) {
285318
ctrl.highlightCallback(function () {
286-
scope.$eval(iAttrs.onhighlight);
319+
scope.$eval(attrs('onhighlight'));
287320
});
288321
}
289322

0 commit comments

Comments
 (0)