codemirror-console

3.2.0 • Public • Published

codemirror-console Build Status

This library add Console to CodeMirror.

This library could execute CodeMirror editor's code.

Installation

npm install codemirror-console

If you want to use it as UI library, please use codemirror-console-ui instead of it.

Usage

open index.html

const MirrorConsole = require("codemirror-console");
const content = document.querySelector(".content");
const editor = new MirrorConsole();
editor.setText(content.textContent);
editor.swapWithElement(content); // insert editor
const consoleMock = {
    log: function (arg) {
        function line(text) {
            var div = document.createElement("div");
            div.appendChild(document.createTextNode(text));
            return div;
        }
        document.getElementById("output").appendChild(line(arg));
    }
}
// eval code
editor.runInContext({ console: consoleMock }, function (error, result) {
    if (error) {
        console.error(error);
    }
});
editor.destroy();// remote editor

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT

Package Sidebar

Install

npm i codemirror-console

Weekly Downloads

225

Version

3.2.0

License

MIT

Unpacked Size

456 kB

Total Files

6

Last publish

Collaborators

  • azu