- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试创建一个 highlight.js 指令,但在应用范围变量时遇到了问题。
<script src="http://code.jquery.com/jquery-1.8.2.min.js" ></script>
<link rel="stylesheet" href="http://yandex.st/highlightjs/7.3/styles/default.min.css">
<script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
<div ng-app="app">
<div ng-controller="MyCtrl">
<snippet><script src="{{src}}"></script></snippet>
{{src}}
</div>
</div>
function MyCtrl($scope) {
$scope.src = "foo.js";
}
app.directive('snippet', ['$timeout', function($timeout) {
var template = '<pre><code></code></pre>';
return {
restrict: 'E',
compile: function(tElement, tAttrs, transclude) {
var rawCode = tElement.text();
tElement.html(template);
return function(scope, element, attrs) {
$timeout(function() {
scope.$apply(function() {
var formattedCode = hljs.highlightAuto(rawCode);
$(element).find('code').html(formattedCode.value);
});
}, 0);
}
}
}
}]);
这是 fiddle :http://jsfiddle.net/dkrotts/RE7Jj/5/
如您所见,$scope.src 并未在代码片段中应用其值。我做错了什么?
最佳答案
关键是你应该使用$interpolate而不是 $compile
Description of $interpolate
Compiles a string with markup into an interpolation function. This service is used by the HTML $compile service for data binding. See $interpolateProvider for configuring the interpolation markup.
当您使用$complie 时,它会将您的字符串转换为元素。
Description of $compile
Compiles a piece of HTML string or DOM into a template and produces a template function, which can then be used to link scope and the template together.
(老实说,在尝试之前我并不真正理解描述。)
这是工作 plunk
app.controller('MainCtrl', function($scope) {
$scope.cdnPath = "//path/to/cdn/";
$scope.version = "1.0";
});
app.directive('snippet', ['$timeout', '$interpolate', function($timeout, $interpolate) {
return {
restrict: 'E',
template:'<pre><code ng-transclude></code></pre>',
replace:true,
transclude:true,
link:function(scope, elm, attrs){
var tmp = $interpolate(elm.find('code').text())(scope);
$timeout(function() {
elm.find('code').html(hljs.highlightAuto(tmp).value);
}, 0);
}
};
}]);
关于javascript - AngularJS + highlight.js(用指令中的表达式评估字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13385535/
我有一个 NSButton带有图像(没有文本),在蓝色背景上。 样式为“Square”,类型为“Momentary Push In”,无边框等。 当我单击按钮时,它周围有一个光矩形,它会突出显示一秒钟
有没有办法用 highlight.js 强调线条? 例如,通过对它们进行不同的着色、更改背景颜色或其他方式。 最佳答案 您可以使用 HTML5 的 mark标签。 让我们以这段 Java 代码为例:
我试图用 highlight.js 做一个简单的例子,但我无法让它工作。我不熟悉highlight.js。这是我的代码,我不知道它有什么问题。任何的想法!提前致谢。 hljs.initHi
原标题是“特定于语言的配色方案防止较简单的配色方案为某些特定于语言的标签着色” 我正在使用 gVim 7.3(在 Ubuntu 12.04 Arch x86/64 上,这很重要)。 更新(2013-0
我将我认为有用的代码示例作为文本文件保存在我的计算机上。我将它们存储为 txt 文件而不是编写它们的语言,以便它们将在 Notepad++ 中打开而不是在编辑器中打开(即我不希望我的 c++ 示例在
所以我在网上搜索了这个问题的解决方案,但到目前为止还没有成功。我正在尝试根据 ASP.NET 中 GridView 中的“突出显示”行更新 SQL 数据库。这是我目前用于突出显示的代码。 //ASP.
如何配置 GitHub 的 Atom 以使其根据名称和/或扩展名自动为文件名设置特定的语法突出显示? 具体来说,我希望它自动将 Ruby 语法高亮设置为 Cocoapods 的 Podfile s。
真的需要一些建议。我正在尝试做几件事。1) 将表格 View 的第一个单元格设置为在第一次加载表格时突出显示。然后用户可以继续选择/突出显示表格中的其他单元格。如何第一次突出显示单元格? 2) 对一行
是否有一些现成的功能/宏可以帮助在不同颜色的源洞察中突出显示不同的单词(原始安装允许突出显示不同的单词,但都以相同的颜色)。 最佳答案 我正在寻找同样的东西。但是从sourceinsight官方引用来
在科莫多中,您的代码块用垂直虚线突出显示,如下图所示 . geany有类似的东西吗? 最佳答案 由于这里没有人回答我,我写信给 geany 邮件列表,他们也向我展示了如何在 geany 中获取它:它被
我正在寻找一个用 JavaScript 编写的全面的语法高亮器,它会自动检测所使用的语言并应用正确的语法高亮。 我从一个简单的谷歌搜索中找到了无数,但它们都必须在 上有某种格式化的类。元素如 .
我正在使用 Lucene 的 Highlighter 类来突出显示匹配搜索结果的片段,并且效果很好。我想从使用 StandardAnalyzer 搜索切换到 EnglishAnalyzer,它将执行词
无论文件类型如何,我都想突出显示某个单词。在我的 .vimrc 中,我添加了: highlight link notes todo syntax match notes contained "TODO
我将 jupyter notebook 与 python 一起使用 db.py 库进行数据库查询。 例如,它可能看起来像(在我的代码单元中): df = db.query(""" SELECT a,b
Closed. This question is off-topic。它当前不接受答案。 想要改善这个问题吗? Update the question,所以它是用于堆栈溢出的on-topic。 已关闭
我如何让它工作,我确实在 nano.rc 和 .nanorc 中添加了颜色语法突出显示配置,但没有任何 react 。 最佳答案 将名为 HOME 的环境变量设置到您的用户目录(cd ~ 将您置于例如
是否可以在 pre 标签中添加一个类来禁用代码高亮?我尝试添加类 prettyprint-false 和 no-prettyprint。 https://code.google.com/p/googl
我在 TextMate2 中工作,但这个问题也可能适用于其他文本编辑器。 我的脚本在 R 中。我打算在脚本上使用 rmarkdown::render() 来创建一个 "report" . 这些报告的聪
我需要在我的网站上发布SAS代码。但是,如果我确实编写HTML来突出显示SAS cod,那将花费我很长时间。 如何将SAS代码转换为外观漂亮的HTML副本? 最佳答案 我只是将您的编辑器中的内容复制/
我想在另一个扩展名上强制突出显示HTML语法(我的一位同事已决定为其模板文件使用其他文件命名方案)。 在其他编辑器中,可以手动选择,但Textmate似乎不适合我。如何使这些.randomtexten
我是一名优秀的程序员,十分优秀!