Skip to content

Instantly share code, notes, and snippets.

@happygrizzly
Forked from mikomatic/ng-prism.js
Last active September 11, 2015 06:21
Show Gist options
  • Save happygrizzly/3461ee289ff8ee64fa14 to your computer and use it in GitHub Desktop.
Save happygrizzly/3461ee289ff8ee64fa14 to your computer and use it in GitHub Desktop.
Angularjs directive with prism code highlight
/**
* Usage
*
* <ng-prism class="language-css">
* body {
* color: red;
* }
* </ng-prism>
*
* the files prismjs and prism css must be included in HTML, use class "language-XXX" to specify language
* */
app.directive('ngPrism',['$interpolate', function ($interpolate) {
"use strict";
return {
restrict: 'E',
template: '<pre><code ng-transclude></code></pre>',
replace: true,
transclude: true,
link: function (scope, elm) {
var tmp = $interpolate(elm.find('code').text())(scope);
elm.find('code').html(Prism.highlightElement(tmp).value);
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment