编译指令AngularJS内部指令指令、AngularJS

2023-09-13 04:08:45 作者:距離產生美°

我试图使用 HighlightJS 上&LT指令; pre方式>由降价指令

I am trying to use a HighlightJS directive on <pre> blocks rendered by a Markdown directive.

的下面是一个plunker重现问题:的结果 http://plnkr.co/edit/qZlMkjNZglV453caNphy?p=$p$pview

在这个例子:

<btf-markdown>
#Markdown directive
<pre hljs>

    angular.forEach($scope.items,function(item){
      console.log(item);
    });
</pre>
</btf-markdown>

我期望&LT; pre&GT; 块的话,被 hljs 解析但没有。

I would expect the <pre> block to get parsed by hljs but does not.

我必须手动调用内部指令的编写?

Do I have to manually invoke the compilation of the inner directive?

推荐答案

btford.markdown 你的 element.html(HTML); 是覆盖 hljs

而不是:

var html = converter.makeHtml(element.text());
element.html(html);

我想你会preFER:

I think you'd prefer:

var html = converter.makeHtml(element.html());
element.html(html);

开关 element.text() element.html()

所以你转换整个HTML元素(包括你的 hljs - 这是不是在 element.text())。

So you're converting the whole html element (including your hljs - which isn't in element.text()).

下面是更新plunker: http://plnkr.co/edit/cURJ1QRfJRheOxTvYc1p? p = preVIEW

Here's the updated plunker: http://plnkr.co/edit/cURJ1QRfJRheOxTvYc1p?p=preview

 
精彩推荐