fast72 commited on
Commit
8852ddc
·
verified ·
1 Parent(s): 83c4a31

Update public/index.html

Browse files
Files changed (1) hide show
  1. public/index.html +58 -93
public/index.html CHANGED
@@ -1,100 +1,65 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>CodeMirror 6 - Editor dengan Pre</title>
7
- <style>
8
- body { font-family: Arial, sans-serif; margin: 20px; }
9
- pre { background: #f5f5f5; padding: 10px; border: 1px solid #ddd; }
10
- #editor-container { height: 500px; border: 1px solid #ddd; margin-top: 10px; }
11
- select, button, label { margin: 5px; padding: 8px; font-size: 16px; }
12
- </style>
13
- </head>
14
- <body>
15
- <h2>CodeMirror 6 Editor</h2>
16
- <select id="language">
17
- <option value="javascript">JavaScript</option>
18
- <option value="python">Python</option>
19
- <option value="html">HTML</option>
20
- <option value="css">CSS</option>
21
- <option value="php">PHP</option>
22
- <option value="java">Java</option>
23
- <option value="cpp">C++</option>
24
- <option value="c">C</option>
25
- <option value="sql">SQL</option>
26
- <option value="xml">XML</option>
27
- <option value="rust">Rust</option>
28
- <option value="go">Go</option>
29
- </select>
30
- <button onclick="downloadFile()">Download</button>
31
- <label><input type="checkbox" id="wrapCode"> Wrap Code</label>
32
-
33
- <pre id="code-preview">// Start coding...</pre>
34
- <div id="editor-container"></div>
35
-
36
- <script type="module">
37
- import { basicSetup } from "https://cdn.skypack.dev/@codemirror/basic-setup";
38
- import { EditorView, keymap, lineWrapping } from "https://cdn.skypack.dev/@codemirror/view";
39
- import { EditorState } from "https://cdn.skypack.dev/@codemirror/state";
40
- import { indentWithTab } from "https://cdn.skypack.dev/@codemirror/commands";
41
- import { javascript } from "https://cdn.skypack.dev/@codemirror/lang-javascript";
42
- import { python } from "https://cdn.skypack.dev/@codemirror/lang-python";
43
- import { html } from "https://cdn.skypack.dev/@codemirror/lang-html";
44
- import { css } from "https://cdn.skypack.dev/@codemirror/lang-css";
45
- import { php } from "https://cdn.skypack.dev/@codemirror/lang-php";
46
- import { java } from "https://cdn.skypack.dev/@codemirror/lang-java";
47
- import { cpp } from "https://cdn.skypack.dev/@codemirror/lang-cpp";
48
- import { c } from "https://cdn.skypack.dev/@codemirror/lang-c";
49
- import { sql } from "https://cdn.skypack.dev/@codemirror/lang-sql";
50
- import { xml } from "https://cdn.skypack.dev/@codemirror/lang-xml";
51
- import { rust } from "https://cdn.skypack.dev/@codemirror/lang-rust";
52
- import { go } from "https://cdn.skypack.dev/@codemirror/lang-go";
53
-
54
- const languageModes = { javascript, python, html, css, php, java, cpp, c, sql, xml, rust, go };
55
 
56
- let editor;
57
- function createEditor(language = "javascript") {
58
- if (editor) editor.destroy();
59
-
60
- const codePreview = document.getElementById("code-preview");
61
- const initialCode = codePreview.textContent;
62
-
63
- const startState = EditorState.create({
64
- doc: initialCode,
65
- extensions: [
66
- basicSetup,
67
- keymap.of([indentWithTab]),
68
- languageModes[language]()
69
- ]
70
- });
71
-
72
- editor = new EditorView({
73
- state: startState,
74
- parent: document.getElementById("editor-container")
75
- });
 
 
76
 
77
- codePreview.style.display = "none";
78
- }
79
 
80
- document.getElementById("language").addEventListener("change", function() {
81
- createEditor(this.value);
82
- });
83
 
84
- document.getElementById("wrapCode").addEventListener("change", function() {
85
- editor.dispatch({ effects: lineWrapping.of(this.checked) });
86
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
- function downloadFile() {
89
- const content = editor.state.doc.toString();
90
- const blob = new Blob([content], { type: "text/plain" });
91
- const a = document.createElement("a");
92
- a.href = URL.createObjectURL(blob);
93
- a.download = "code.txt";
94
- a.click();
95
- }
96
 
97
- createEditor();
98
  </script>
99
- </body>
100
- </html>
 
1
+ <!doctype html>
2
+ <meta charset=utf8>
3
+ <title>CM6 demo</title>
4
+ <link rel="stylesheet" href="https://unpkg.com/@datavis-tech/codemirror-6-prerelease@5.0.0/codemirror.next/legacy-modes/style/codemirror.css">
5
+ <script src="https://unpkg.com/@datavis-tech/codemirror-6-prerelease@5.0.0/dist/codemirror.js"></script>
6
+ <style>
7
+ .codemirror { height: 300px; overflow: auto; border: 1px solid silver}
8
+ .codemirror-matching-bracket { background: red; }
9
+ .codemirror-nonmatching-bracket { background: green; }
10
+ </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ <body>
13
+ <h1>CM6</h1>
14
+ <div id=editor></div>
15
+ <script>
16
+ let {
17
+ EditorState,
18
+ EditorView,
19
+ keymap,
20
+ history,
21
+ redo,
22
+ redoSelection,
23
+ undo,
24
+ undoSelection,
25
+ lineNumbers,
26
+ baseKeymap,
27
+ indentSelection,
28
+ legacyMode,
29
+ legacyModes: { javascript },
30
+ matchBrackets,
31
+ specialChars,
32
+ multipleSelections
33
+ } = CodeMirror;
34
 
35
+ let mode = legacyMode({mode: javascript({indentUnit: 2}, {})})
 
36
 
37
+ let isMac = /Mac/.test(navigator.platform)
38
+ let state = EditorState.create({doc: `"use strict";
39
+ const {readFile} = require("fs");
40
 
41
+ readFile("package.json", "utf8", (err, data) => {
42
+ console.log(data);
43
+ });`, extensions: [
44
+ lineNumbers(),
45
+ history(),
46
+ specialChars(),
47
+ multipleSelections(),
48
+ mode,
49
+ matchBrackets(),
50
+ keymap({
51
+ "Mod-z": undo,
52
+ "Mod-Shift-z": redo,
53
+ "Mod-u": view => undoSelection(view) || true,
54
+ [isMac ? "Mod-Shift-u" : "Alt-u"]: redoSelection,
55
+ "Ctrl-y": isMac ? undefined : redo,
56
+ "Shift-Tab": indentSelection
57
+ }),
58
+ keymap(baseKeymap),
59
+ ]})
60
 
61
+ let view = new EditorView({state})
62
+ document.querySelector("#editor").appendChild(view.dom)
 
 
 
 
 
 
63
 
 
64
  </script>
65
+ </body>