pocketlang/docs/pages/Getting Started/try it now.html

33 lines
851 B
HTML
Raw Normal View History

2021-05-13 03:28:44 +08:00
<main id="code-editor">
<div id="try-title">
<p>code editor</p> <a id="run-button">run</a>
</div>
<div class="editor language-ruby" id="code-area">print('hello world!')</div>
<p>output</p>
<pre><div id="output">...</div></pre>
</main>
<script type="module">
const editor = document.querySelector('.editor')
const highlight = editor => {
// highlight.js does not trim old tags,
// let's do it by this hack.
editor.textContent = editor.textContent;
editor.innerHTML = Prism.highlight(editor.textContent, Prism.languages.ruby, 'ruby');
}
const jar = CodeJar(editor, withLineNumbers(highlight), {
indentOn: /[(\[{]$/
})
jar.updateCode(localStorage.getItem('code'))
jar.onUpdate(code => {
localStorage.setItem('code', code)
})
</script>
<script async type="text/javascript" src="{{ STATIC_DIR }}try_now.js"></script>