尝试将highlight.js集成到使用requirejs的角度应用程序中

时间:2013-11-22 08:48:06

标签: javascript angularjs requirejs syntax-highlighting

所以我正在尝试制作一个简单的小型粘贴盒,这对我来说主要是一项技术学习练习。除了highlight.js(任意选择的库)

之外,我在前端工作了一切

这是我的控制器

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();
            }];
 });

和我的观点

 <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>

公平地说这个代码可行,问题是{{code}}似乎正在清理正在吐出的html,所以我需要找到另一种方法来做到这一点。尝试了一些其他的图书馆但没有进展。

1 个答案:

答案 0 :(得分:1)

如果问题是{{code}}正在消毒,您是否尝试过ngBindHtmlUnsafe

<pre ng-controller="Render">
    <code class="pre-scrollable" ng-bind-html-unsafe="code"></code>
</pre>
相关问题