mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 07:01:33 +00:00
Rework onmessage
This commit is contained in:
parent
fac9202b3d
commit
18c8f45a19
@ -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);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user