From 67c36e008957cbbf940c6891a930cc4f81660315 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 23 May 2019 15:51:56 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=9B=B4=E6=96=B0=20Playground=20?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/playgrounds.go | 2 +- static/js/playground.js | 14 +++++++++++--- views/playground/index.html | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/playground/playgrounds.go b/playground/playgrounds.go index ea35788..490a413 100644 --- a/playground/playgrounds.go +++ b/playground/playgrounds.go @@ -55,7 +55,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { // try to load file code := conf.HelloWorld - fileName := "8b7cc38b4c12e6fde5c4d15a4f2f32e5.go" // MD5 of HelloWorld.go + fileName := "6c5595ec6fbadf4cfce3edbfcfd8c6d0.go" // MD5 of HelloWorld.go if strings.HasSuffix(r.URL.Path, ".go") { fileNameArg := r.URL.Path[len("/playground/"):] diff --git a/static/js/playground.js b/static/js/playground.js index 32411e8..e170422 100644 --- a/static/js/playground.js +++ b/static/js/playground.js @@ -303,11 +303,19 @@ var playground = { playground.pid = data.pid; - var output = data.output; + var output = $("#output").html(); + if ("" === output) { + output = "
" + data.output + "
"; + } else { + output = output.replace(/<\/pre>$/g, data.output + ''); + } output = output.replace(/\r/g, ''); output = output.replace(/\n/g, '
'); - var oldOutput = $("#output").html(); - $("#output").html(oldOutput + output); + if (-1 !== output.indexOf("
")) { + output = Autolinker.link(output); + } + + $("#output").html(output); }; playgroundWS.onclose = function (e) { console.log('[playground onclose] disconnected (' + e.code + ')'); diff --git a/views/playground/index.html b/views/playground/index.html index f8c8957..608e7e8 100644 --- a/views/playground/index.html +++ b/views/playground/index.html @@ -98,7 +98,7 @@ - +