File size: 794 Bytes
6b5c3aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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();
}