Question

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)

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top