Ace Editor autocomplete and multiple languages

可紊 提交于 2019-12-08 02:06:10

问题


How can I create an autocomplete and how to highlight html, javascript and css inside php for the Ace editor http://ace.ajax.org/.

<html>
    <head>
        <title><?=$title; ?></title>
        <style>
            body {
                background: black;
                color: white;
            }
        </style>
        <script>
            alert("this is only a no-sense test script....");
        </script>
    </head>
    <body>
        This is only a no-sense test script but I want that html tags, css styles and javascript code are highlighted....<br />
        Is it possible?
    </body>
</html>

(sorry for my english)


回答1:


These are two questions.

  1. How can I create an autocompleter that completes PHP?

  2. How can I syntax highlight HTLM code inside PHP code?

For the second question, there is some discussion in the Google group for Ace Editor In my opinion, the question is not really answered if it is possible or not, but it seems at least doable. Have a look at the documentation for highlighter, especially about the part "Embedding a different highlighter".

For autocompletion, I don't see a chance at all. See the Google group entry about a similar (recent) question.




回答2:


As of a few months ago the Ace Editor now supports autocomplete (see: http://ace.c9.io/#nav=about)




回答3:


I would like to suggest you can see this project : gherkin-editor. It implements the code complete function upon ace editor




回答4:


For any one still looking around for this, I found exactly what I needed here: https://github.com/ajaxorg/ace/wiki/How-to-enable-Autocomplete-in-the-Ace-editor

I wanted to enable live auto-completion, so there is another option enableLiveAutocompletion and enableSnippets (to give a brief description of the suggestion if available).

I used it like this:

editor.setOptions({
     enableLiveAutocompletion: true,
     enableSnippets: true
 });

There is also an example demonstrating how you could add a custom completer to return results tailored to your specific project.



来源:https://stackoverflow.com/questions/7938985/ace-editor-autocomplete-and-multiple-languages

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