我试图使用 HighlightJS 上&LT指令; pre方式>由块href=\"github/btford/angular-markdown-directive\" rel=\"nofollow\">降价指令
I am trying to use a HighlightJS directive on <pre> blocks rendered by a Markdown directive.
的下面是一个plunker重现问题:的结果 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: plnkr.co/edit/cURJ1QRfJRheOxTvYc1p? p = preVIEW
Here's the updated plunker: plnkr.co/edit/cURJ1QRfJRheOxTvYc1p?p=preview
更多推荐
编译指令AngularJS内部指令
发布评论