Last active
September 7, 2020 22:35
-
-
Save pachacamac/53b4b2e513fd903d0b77062b9fba64be to your computer and use it in GitHub Desktop.
monaco editor
This file contains hidden or 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
<!doctype html> | |
<head> | |
<title>Frontend Playground</title> | |
<meta charset=utf8> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<meta name="robots" content="noindex, nofollow"> | |
<meta name="googlebot" content="noindex, nofollow"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" type="text/css" data-name="vs/editor/editor.main" href="https://unpkg.com/[email protected]/min/vs/editor/editor.main.css"> | |
<script type="text/javascript" src="https://unpkg.com/[email protected]/min/vs/loader.js"></script> | |
<style> | |
html, body, #editor { | |
position: absolute; | |
left: 0; | |
top: 0; | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
overflow: hidden; | |
} | |
#change-content { | |
z-index: 99999; | |
position: absolute; | |
right: 1em; | |
top: 1em; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="editor"></div> | |
<button id="change-content">change content</button> | |
<script> | |
require.config({ paths: { 'vs': 'https://unpkg.com/[email protected]/min/vs' } }); | |
window.MonacoEnvironment = { getWorkerUrl: () => proxy }; | |
let proxy = URL.createObjectURL(new Blob([` | |
self.MonacoEnvironment = { | |
baseUrl: 'https://unpkg.com/[email protected]/min/' | |
}; | |
importScripts('https://unpkg.com/[email protected]/min/vs/base/worker/workerMain.js'); | |
`], { type: 'text/javascript' })); | |
let editor; | |
require(["vs/editor/editor.main"], function () { | |
editor = monaco.editor.create(document.getElementById('editor'), { | |
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'), | |
language: 'javascript', | |
theme: 'vs-dark' | |
}); | |
editor.addListener('didType', () => { | |
console.log(editor.getValue()); | |
}); | |
}); | |
document.getElementById('change-content').addEventListener('click', (e)=>{ | |
editor.setValue(` | |
from time import time | |
def say_what(t): | |
print(f"it's time to high five motherlicka! {t}") | |
say_what(time.time) | |
`.trim()); | |
monaco.editor.setModelLanguage(editor.getModel(), 'python') | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment