From 18c8f45a19575f238e48421d1b66cbe6bb6d19f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Mon, 27 Nov 2017 19:01:32 +0100 Subject: [PATCH] Rework onmessage --- src/app/static/ws_listener.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/app/static/ws_listener.js b/src/app/static/ws_listener.js index 9e19225..5f69055 100644 --- a/src/app/static/ws_listener.js +++ b/src/app/static/ws_listener.js @@ -1,5 +1,9 @@ let ws = new WebSocket('ws://' + document.location.host + '/ws'); +let converter = new showdown.Converter(); + +hljs.initHighlightingOnLoad(); + $('#container').on('click', '.anchor', ( function (event) { let anchorName = $(this).attr('id').replace('_event', ''); @@ -37,5 +41,15 @@ ws.onopen = function () { ws.onmessage = function (messageEvent) { let message = JSON.parse(messageEvent.data); - $('#' + message['anchor']).text(message['data']); + console.log('Receiving: '); + console.log(message); + let $anchor = $('#' + message['anchor']); + if (message['anchor'] === 'anchor_webide') { + let code = hljs.highlightAuto(message['data']); + $anchor.html(code.value); + } + else { + let formatted_message = converter.makeHtml(message['data']); + $anchor.html(formatted_message); + } }; \ No newline at end of file