codemirror-console
v3.2.0
Published
Add execute the code function to CodeMirror.
Downloads
288
Readme
codemirror-console
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
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT