38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
/*
|
|
* Code Example Directive
|
|
*
|
|
* Formats codes examples and prevents
|
|
* Angular code from being processed.
|
|
*/
|
|
|
|
angularIO.directive('codeExample', function() {
|
|
return {
|
|
restrict: 'E',
|
|
|
|
compile: function(tElement, attrs) {
|
|
var html = (attrs.escape === "html") ? _.escape(tElement.html()) : tElement.html();
|
|
var classes = 'prettyprint ' + attrs.format + ' lang-' + attrs.language +
|
|
(attrs.showcase === 'true' ? ' is-showcase' : '');
|
|
var template =
|
|
'<copy-container>' +
|
|
'<pre class="' + classes + '">' +
|
|
'<code ng-non-bindable>' + html + '</code>' +
|
|
'</pre>' +
|
|
'</copy-container>';
|
|
|
|
// UPDATE ELEMENT WITH NEW TEMPLATE
|
|
tElement.html(template);
|
|
|
|
// RETURN ELEMENT
|
|
return function(scope, element, attrs) {};
|
|
}
|
|
};
|
|
});
|
|
|
|
// '<div style="position: relative">' +
|
|
// '<copy-button style="position: absolute; top: 10px; right: 0px; z-index: 1000" ></copy-button>' +
|
|
// '<pre class="' + classes + '">' +
|
|
// '<code ng-non-bindable>' + html + '</code>' +
|
|
// '</pre>' +
|
|
// '</div>';
|