forked from pc035860/angular-highlightjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-highlightjs.min.js
6 lines (6 loc) · 3.29 KB
/
angular-highlightjs.min.js
1
2
3
4
5
6
/*! angular-highlightjs
version: 0.4.3
build date: 2015-08-12
author: Chih-Hsuan Fan
https://github.com/pc035860/angular-highlightjs.git */
!function(a,b){"object"==typeof exports||"object"==typeof module&&module.exports?module.exports=b(require("angular"),require("highlight.js")):"function"==typeof define&&define.amd?define(["angular","hljs"],b):a.returnExports=b(a.angular,a.hljs)}(this,function(a,b){function c(b){var c=!0;return a.forEach(["source","include"],function(a){b[a]&&(c=!1)}),c}var d=a.module("hljs",[]);d.provider("hljsService",function(){var c={};return{setOptions:function(b){a.extend(c,b)},getOptions:function(){return a.copy(c)},$get:function(){return(b.configure||a.noop)(c),b}}}),d.factory("hljsCache",["$cacheFactory",function(a){return a("hljsCache")}]),d.controller("HljsCtrl",["hljsCache","hljsService",function(b,c){var d=this,e=null,f=null,g=null,h=null;d.init=function(a){e=a},d.setLanguage=function(a){f=a,g&&d.highlight(g)},d.highlightCallback=function(a){h=a},d.highlight=function(i){if(e){var j,k;g=i,f?(k=d._cacheKey(f,g),j=b.get(k),j||(j=c.highlight(f,c.fixMarkup(g),!0),b.put(k,j))):(k=d._cacheKey(g),j=b.get(k),j||(j=c.highlightAuto(c.fixMarkup(g)),b.put(k,j))),e.html(j.value),e.addClass(j.language),null!==h&&a.isFunction(h)&&h()}},d.clear=function(){e&&(g=null,e.text(""))},d.release=function(){e=null},d._cacheKey=function(){var a=Array.prototype.slice.call(arguments),b="!angular-highlightjs!";return a.join(b)}}]);var e,f,g,h;return e=["$compile","$parse",function(b,d){return{restrict:"EA",controller:"HljsCtrl",compile:function(e,f,g){var h=e[0].innerHTML.replace(/^(\r\n|\r|\n)/m,""),i=e[0].textContent.replace(/^(\r\n|\r|\n)/m,"");return e.html('<pre><code class="hljs"></code></pre>'),function(e,f,g,j){var k,l;if(a.isDefined(g.compile)&&(k=d(g.compile)),a.isDefined(g.escape)?l=d(g.escape):a.isDefined(g.noEscape)&&(l=d("false")),j.init(f.find("code")),g.onhighlight&&j.highlightCallback(function(){e.$eval(g.onhighlight)}),(h||i)&&c(g)){var m;m=l&&!l(e)?i:h,j.highlight(m),k&&k(e)&&b(f.find("code").contents())(e)}e.$on("$destroy",function(){j.release()})}}}}],f=function(b){return[function(){return{require:"?hljs",restrict:"A",link:function(c,d,e,f){f&&e.$observe(b,function(b){a.isDefined(b)&&f.setLanguage(b)})}}}]},g=function(b){return["$compile","$parse",function(c,d){return{require:"?hljs",restrict:"A",link:function(e,f,g,h){var i;h&&(a.isDefined(g.compile)&&(i=d(g.compile)),e.$watch(g[b],function(a,b){a?(h.highlight(a),i&&i(e)&&c(f.find("code").contents())(e)):h.clear()}))}}}]},h=function(b){return["$http","$templateCache","$q","$compile","$parse",function(c,d,e,f,g){return{require:"?hljs",restrict:"A",compile:function(h,i,j){var k=i[b];return function(b,h,i,j){var l,m=0;j&&(a.isDefined(i.compile)&&(l=g(i.compile)),b.$watch(k,function(g){var i=++m;if(g&&a.isString(g)){var k,n;k=d.get(g),k||(n=e.defer(),c.get(g,{cache:d,transformResponse:function(a,b){return a}}).success(function(a){i===m&&n.resolve(a)}).error(function(){i===m&&j.clear(),n.resolve()}),k=n.promise),e.when(k).then(function(c){c&&(a.isArray(c)?c=c[1]:a.isObject(c)&&(c=c.data),c=c.replace(/^(\r\n|\r|\n)/m,""),j.highlight(c),l&&l(b)&&f(h.find("code").contents())(b))})}else j.clear()}))}}}}]},d.directive("hljs",e).directive("language",f("language")).directive("source",g("source")).directive("include",h("include")),"hljs"});