Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to show hidden characters in CodeMirror?

Tags:

codemirror

Is it possible to show hidden characters (like Carriage Return character) in Codemirror Text Editor, but I've not found any configuration reference about it in its documentation. Is it possible do this?

like image 533
Dr. No Avatar asked Oct 08 '13 11:10

Dr. No


People also ask

How do you reveal hidden characters?

As with most things in Word, you can use either a keyboard shortcut or the mouse to see the hidden formatting characters. Keyboard, hit Control+Shift+8. Mouse, simply click the Show/Hide button on the Home tab.

How do I setup a code mirror?

Download CodeMirror files. Download jQuery file. Inside the codemirror project folder create subfolders and name them js, css and plugin. The js folder will hold all the javascript files.

How do I use CodeMirror in textarea?

This could be used to, for example, replace a textarea with a real editor: var myCodeMirror = CodeMirror(function(elt) { myTextArea. parentNode. replaceChild(elt, myTextArea); }, {value: myTextArea.


1 Answers

This could be done with help of overlays and predefined styles with whitespace and EOL symbol this way:

cm.addOverlay({
    name: 'invisibles',
    token:  function nextToken(stream) {
        var ret,
            spaces  = 0,
            peek    = stream.peek() === ' ';

        if (peek) {
            while (peek && spaces < Maximum) {
                ++spaces;

                stream.next();
                peek = stream.peek() === ' ';
            }

            ret = 'whitespace whitespace-' + spaces;
        } else {
            while (!stream.eol() && !peek) {
                stream.next();

                peek = stream.peek() === ' ';
            }

            ret = 'cm-eol';
        }

        return ret;
    }
});

You could use addon CodeMirror Show Invisibles for this purpose.

like image 190
coderaiser Avatar answered Sep 22 '22 04:09

coderaiser