0

So I'm trying to make a simple little pastebin, this is mostly a tech learning exercise for me. I've got everything working on the frontend except highlight.js (library chosen arbitrarily)

Here's my controller

define([
    'highlight',
    'angular',
], function( hl ) {
    'use strict';

    return [      '$scope', '$location', '$routeParams', 'pastes',
            function ( $scope,   $location,   $routeParams,   pastes ) {
                    console.log( pastes );
                    var digest  = $routeParams.digest;
                    if ( pastes[digest] ) {
                            $scope.code = hl.highlightAuto( pastes[digest] ).value;
                            console.log( $scope.code );
                    }
                    $scope.view = function( view ) {
                            $location.path( view );
                    }
                    $scope.$apply();
            }];
 });

and my view

 <pre ng-controller="Render"><code class="pre-scrollable">
 {{code}}
 </code></pre>
 <button
    type="button"
    class="btn btn-primary pull-right"
    ng-click="view('/')"
 >New Paste</button>

to be fair this code works, the problem is that {{code}} seems to be sanitizing the html that is being spit out, so I need to find another way to do this. Tried a few other incantations of the library but no progress.

1
  • here's all my code in case I've left off a relevant bit Commented Nov 22, 2013 at 8:48

1 Answer 1

1

If the problem is {{code}} being sanitized, have you tried ngBindHtmlUnsafe?

<pre ng-controller="Render">
    <code class="pre-scrollable" ng-bind-html-unsafe="code"></code>
</pre>
Sign up to request clarification or add additional context in comments.

1 Comment

in this case it appears just ng-bind-html will work after I loaded ngSanitize into my angular module. I did not know about this prior, thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.