README
CodeEditor
A generic React component for building customized code editors, based on Draft.js.
Demo
This simple C++ editor demo. exercises all the capabilities of the component, which right now are:
- Automatic indentation inside blocks (delimited by { and }); you can set the indent size.
- Customizable syntax highlighting.
- Automatically closing a block and starting a new line when the user opens a block (i.e. inserting a '}' automatically).
- Passing a callback for when the code is changed.
Usage
This is the entire code of the demo page:
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>CodeEditor demo</title>
<script type="text/javascript" src="bundle.js"></script>
<style type="text/css">
#editor {
width: 100%;
height: 100%;
}
</style>
<script type="text/javascript">
function loadEditor() {
var editor = document.getElementById("editor");
CodeEditor.render(editor, {
style: {
width: '50%',
height: '20em',
border: '1px solid black',
fontFamily: 'monospace',
fontSize: '2em',
},
autoIndent: true,
autoCloseBlocks: true,
highlightingRules: [
// Some keywords
{
regex: 'return|do|while|for|if|else|template|struct|class|using|namespace',
style: {fontWeight: 'bold'},
},
// Some types
{
regex: 'int|char|void|short|unsigned|long|size_t|clock_t',
style: {fontWeight: 'bold', color: '#000088'},
},
// Pre-processor lines
{
regex: '^#.*