| const editor = CodeMirror.fromTextArea(document.getElementById('code'), { |
| mode: "javascript", |
| theme: "default", |
| lineNumbers: true, |
| indentWithTabs: true, |
| tabSize: 4, |
| matchBrackets: true, |
| autoCloseBrackets: true, |
| lineWrapping: false |
| }); |
|
|
| document.getElementById('language').addEventListener('change', function() { |
| editor.setOption("mode", this.value); |
| editor.setValue(`// Hello, ${this.value}!`); |
| }); |
|
|
| document.getElementById('wrapCode').addEventListener('change', function() { |
| editor.setOption("lineWrapping", this.checked); |
| }); |
|
|
| function downloadFile() { |
| const content = editor.getValue(); |
| const blob = new Blob([content], { type: "text/plain" }); |
| const a = document.createElement("a"); |
| a.href = URL.createObjectURL(blob); |
| a.download = "code.txt"; |
| a.click(); |
| } |