I'm trying to build a syntax highlighting directive.
Basically a directive like so:
<div syntax-highlight="language">{{codeValue}}</div>
Should be turned into:
<div syntax-highlight="language">
<pre><code>{{codeValue that has been syntax highlighted with span tags}}</code></pre>
</div>
So what I have is:
return {
scope: {
'syntaxHighlight': '@'
},
template: '<pre><code ng-transclude></code></pre>',
transclude: true,
link: function (scope, element, attributes, controller, transclude) {
}
};
When this code currently runs, everything that is inside the {{codeValue}} which is basically a string gets put into <code ng-transclude></code> while being wrapped in a span element.
This is not good because I don't just want a string inside the code element. I need to modify this value prior to being transcluded.
I need to pass this {{codeValue}} into a syntax highlighting function which will return the syntax highlighted code which will be raw HTML (so a raw string (sanitized and escaped) gets turned into HTML with span tags). This raw HTML then needs to be put inside code element.
I've tried using the transclude function, but it seems like the content has already been transcluded.