From 04d74c081e17cc03fa16bca5c1ae7e6a65ae8718 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Tue, 1 Oct 2013 11:20:35 +1000 Subject: [PATCH] go.tools: sync play.js from go.talks R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/14177043 --- godoc/static/play.js | 17 ++++++++++------- godoc/static/static.go | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/godoc/static/play.js b/godoc/static/play.js index a8b83bc5..20350fad 100644 --- a/godoc/static/play.js +++ b/godoc/static/play.js @@ -13,17 +13,20 @@ function initPlayground(transport) { var s = ""; for (var i = 0; i < node.childNodes.length; i++) { var n = node.childNodes[i]; - if (n.nodeType !== 1) continue; - if (n.tagName === "BUTTON") continue; - if (n.tagName === "SPAN" && n.className === "number") continue; - if (n.tagName === "PRE"){ + if (n.nodeType === 1) { + if (n.tagName === "BUTTON") continue + if (n.tagName === "SPAN" && n.className === "number") continue; + if (n.tagName === "DIV" || n.tagName == "BR") { + s += "\n"; + } s += text(n); continue; } - var innerText = n.innerText === undefined ? "textContent" : "innerText"; - s += n[innerText] + "\n"; + if (n.nodeType === 3) { + s += n.nodeValue; + } } - return s; + return s.replace("\xA0", " "); // replace non-breaking spaces } function init(code) { diff --git a/godoc/static/static.go b/godoc/static/static.go index 41fbc5bb..a4649696 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -847,17 +847,20 @@ function initPlayground(transport) { var s = ""; for (var i = 0; i < node.childNodes.length; i++) { var n = node.childNodes[i]; - if (n.nodeType !== 1) continue; - if (n.tagName === "BUTTON") continue; - if (n.tagName === "SPAN" && n.className === "number") continue; - if (n.tagName === "PRE"){ + if (n.nodeType === 1) { + if (n.tagName === "BUTTON") continue + if (n.tagName === "SPAN" && n.className === "number") continue; + if (n.tagName === "DIV" || n.tagName == "BR") { + s += "\n"; + } s += text(n); continue; } - var innerText = n.innerText === undefined ? "textContent" : "innerText"; - s += n[innerText] + "\n"; + if (n.nodeType === 3) { + s += n.nodeValue; + } } - return s; + return s.replace("\xA0", " "); // replace non-breaking spaces } function init(code) {