ng-factory
Version:
AngularJS industrialized development
28 lines (20 loc) • 881 B
JavaScript
;
angular.module('ngFactory')
.directive('appendSource', function($window, $compile, $hljs, indent) {
return {
compile: function(element, attr) {
// Directive options
var options = {placement: 'after'};
angular.forEach(['placement', 'hlClass'], function(key) {
if(angular.isDefined(attr[key])) options[key] = attr[key];
});
var hlElement = angular.element('<div class="highlight" ng-non-bindable><pre><code class="html" style="margin:0"></code></pre></div>');
var codeElement = hlElement.children('pre').children('code');
var elementHtml = indent(element.html());
codeElement.text(elementHtml);
if(options.hlClass) codeElement.addClass(options.hlClass);
element[options.placement](hlElement);
$hljs.highlightBlock(codeElement[0]);
}
};
});