【发布时间】:2013-12-03 14:26:37
【问题描述】:
我有一个.tmlanguage 文件,它在Sublime Text 2 中运行良好,并根据需要突出显示所有内容。但我无法将其转换为 Ace 突出显示规则。
或者更确切地说,我转换了它,但我在ace.js 主文件中出现错误。
我做什么:
1) 克隆 ace 存储库
2) 导航到ace/tool 并在命令提示符下执行此命令:npm install
3)然后执行这个命令:node tmlanguage.js <path_to_tmlanguage_file>并得到:
parseString is deprecated. Please, use parseStringSync instead.
在ace\lib\ace\mode 目录中创建了两个文件。
4)通过执行cd ..导航到ace主文件夹
5)执行node Makefile.dryice.js full得到:
module.js:340
throw err;
^
Error: Cannot find module 'dryice'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (E:\myPath\ace\Makefile.
dryice.js:38:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
6) 必须在 /ace 主文件夹中执行 npm install 然后再次调用 node Makefile.dryice.js full 来构建项目。
现在构建的文件被复制到ace/build 文件夹。
假设我的 html 文件和 /ace 文件夹在同一个文件夹中。这是来自 html 的一个块:
<script src="ace/build/src-noconflict/ace.js"></script>
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/slbeclipse");
</script>
在ace\build\src-noconflict 文件夹中,我有mode-slbeclipse.js 文件。
7) 在 chrome(或其他浏览器)中打开此 html 文件并获取(在控制台选项卡中):
Uncaught TypeError: object is not a function ace.js:8018
这是第 8018 行:
this.moveCursorTo(row, column);
8) 设置断点 -> 第一次命中this.moveCursorTo 是undefined 但没有抛出错误,第二次抛出错误。
9) 将该行更改为:
if(this.moveCursorTo)
{
this.moveCursorTo(row, column);
}
比我在第 8564 行得到错误:Uncaught TypeError: object is not a function:
this.getTokenizer = function() {
if (!this.$tokenizer) {
this.$highlightRules = new this.HighlightRules();
// here the exception occures
this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
}
return this.$tokenizer;
};
10) 尝试多次调试和编辑ace.js 文件 - 其他地方出现错误。
Sublime Text 2 正确使用.tmlanguage 并且所有内容都被突出显示。所以,我认为,问题应该出在ace 或者(我希望)这是我的错,我遗漏了一些明显的东西。
【问题讨论】:
标签: syntax-highlighting npm ace-editor