mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 11:52:54 +00:00 
			
		
		
		
	Replace roll-your-own basic WebIDE with Ace Editor
This commit is contained in:
		@@ -1,6 +1,11 @@
 | 
			
		||||
let ws = new WebSocket('ws://' + document.location.host + '/ws');
 | 
			
		||||
 | 
			
		||||
let converter = new showdown.Converter();
 | 
			
		||||
// TODO: don't hardcode anchor id
 | 
			
		||||
let editor = ace.edit('anchor_webide');
 | 
			
		||||
editor.setTheme('ace/theme/monokai');
 | 
			
		||||
editor.getSession().setMode('ace/mode/python');
 | 
			
		||||
editor.$blockScrolling = Infinity;
 | 
			
		||||
 | 
			
		||||
$('#container').on('click', '.anchor', ( function (event) {
 | 
			
		||||
    let anchorName = $(this).attr('id').replace('_event', '');
 | 
			
		||||
@@ -42,8 +47,7 @@ ws.onmessage = function (messageEvent) {
 | 
			
		||||
    console.log(message);
 | 
			
		||||
    let $anchor = $('#' + message['anchor']);
 | 
			
		||||
    if (message['anchor'] === 'anchor_webide') {
 | 
			
		||||
        let code = hljs.highlightAuto(message['data']);
 | 
			
		||||
        $anchor.html(code.value);
 | 
			
		||||
        editor.setValue(message['data'], -1);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        let formatted_message = converter.makeHtml(message['data']);
 | 
			
		||||
 
 | 
			
		||||
@@ -42,6 +42,7 @@
 | 
			
		||||
    <script src="{{ static_url('vendor/js/bootstrap.min.js') }}" defer></script>
 | 
			
		||||
    <script src="{{ static_url('vendor/js/highlight.min.js') }} defer"></script>
 | 
			
		||||
    <script src="{{ static_url('vendor/js/showdown.min.js') }} defer"></script>
 | 
			
		||||
    <script src="{{ static_url('vendor/js/ace/ace.js') }} defer"></script>
 | 
			
		||||
    <script src="{{ static_url('ws_listener.js') }}" defer></script>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -1,9 +1,6 @@
 | 
			
		||||
<h1>Source code</h1>
 | 
			
		||||
<pre>
 | 
			
		||||
    <code id="{{ anchor_id }}">
 | 
			
		||||
         
 | 
			
		||||
    </code>
 | 
			
		||||
</pre>
 | 
			
		||||
<div  id="{{ anchor_id }}" class="mt-3 mb-3">
 | 
			
		||||
</div>
 | 
			
		||||
<button type="button" class="btn btn-outline-primary anchor" id="{{ anchor_id }}_event">
 | 
			
		||||
    Next
 | 
			
		||||
</button>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user