How to add emmet support in ace js code editor?

会有一股神秘感。 提交于 2019-12-09 06:44:47

问题


I am trying to embed ace code editor in my project. I am initializing my code editor with following code and now I want to enable emmet js features. I can see the ext-emmet.js extension is already their in the src directory of ace.js pre-packaged version

I need help in enabling emmet extension features. So here is my initialization code.

  var e = ace.edit("editorId"); // id of the code editor div 
  e.setTheme("ace/theme/monokai");
  e.getSession().setMode("ace/mode/html");
  e.setBehavioursEnabled(true);
  e.getSession().setTabSize(2);

Obviously I am adding the ace.js on top of the page. I can provide more details if needed.


回答1:


See Lines 539-543 in ace demo.

Basically you need to load emmet source script (e.g. from https://github.com/nightwing/emmet-core/blob/master/emmet.js) and ace extension from /src/ext-emmet.js call require("ace/ext/emmet"); so that requirejs executes the script
And after that call editor.setOption("enableEmmet", true);.
See jsbin.com/ace-emmet/1/edit for live demo.



来源:https://stackoverflow.com/questions/17580711/how-to-add-emmet-support-in-ace-js-code-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!