Skip to content

Instantly share code, notes, and snippets.

@rachaelshaw
Last active April 26, 2016 06:31
Show Gist options
  • Save rachaelshaw/662e690d9dfd31ca59e9 to your computer and use it in GitHub Desktop.
Save rachaelshaw/662e690d9dfd31ca59e9 to your computer and use it in GitHub Desktop.
Using Rainbow syntax highlighter with AngularJS

Using Rainbow with Angular

After following the instructions for setting up Rainbow, include this directive:

/**
 * Directive for using rainbow syntax highlighter with angular
 */

angular.module('MyApp')
.directive('rainbowBlock', function () {

  return {
    restrict: 'A',
    link: function() {
      Rainbow.color();
    }
  };
});

Then add rainbow-block as an attribute on the pre element in the html:

<pre rainbow-block><code data-language="javascript">//my code here</code></pre>

...and it will totally work. Hooray.

@fizerkhan
Copy link

hi, i have a problem. i want to place some variable value inside the code. If i use your code, the variable is not properly placed. output looks like

<span> {{ user.name }} </span>

Here i expect to have value of the name variable.
How to fix it? Can we call Rainbow.color() after everything is placed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment