-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
734743d
commit 5bd5831
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Monaco Editor Example</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs/loader.min.js"></script> | ||
<style> | ||
#container { | ||
width: 800px; | ||
height: 600px; | ||
border: 1px solid grey; | ||
margin: 20px auto; | ||
} | ||
|
||
pre { | ||
word-break: break-all; | ||
width: 100%; | ||
white-space: pre-wrap; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container"></div> | ||
<button id="compileBtn">Compile Code</button> | ||
<pre id="result"></pre> | ||
<script> | ||
// Config for Monaco Editor | ||
require.config({ | ||
paths: { | ||
vs: "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs", | ||
}, | ||
}); | ||
require(["vs/editor/editor.main"], function () { | ||
var editor = monaco.editor.create( | ||
document.getElementById("container"), | ||
{ | ||
value: [ | ||
"using System;", | ||
"public class HelloWorld {", | ||
" public static void Main() {", | ||
' Console.WriteLine("Hello, world!");', | ||
" }", | ||
"}", | ||
].join("\n"), | ||
language: "csharp", | ||
} | ||
); | ||
|
||
document.getElementById("compileBtn").onclick = function () { | ||
var code = editor.getValue(); | ||
compileCode(code); | ||
}; | ||
}); | ||
|
||
function compileCode(code) { | ||
// prepare code as formdata | ||
const formData = new FormData(); | ||
formData.append("code", code); | ||
|
||
// prepare fetch request | ||
fetch("/playground/buildWithRoslyn", { | ||
method: "POST", | ||
body: formData, | ||
}) | ||
.then((response) => response.text()) | ||
.then((data) => { | ||
if (data.error) { | ||
document.getElementById("result").textContent = | ||
"Error: " + data.error; | ||
} else { | ||
document.getElementById("result").textContent = | ||
"Compiled DLL: " + data; | ||
} | ||
}) | ||
.catch((error) => { | ||
document.getElementById("result").textContent = | ||
"Error: " + error.message; | ||
}); | ||
} | ||
</script> | ||
</body> | ||
</html> |