@@ -9,6 +9,10 @@ function allTextNodes(nodes) {
99function getPreWithSource ( ) {
1010 var childNodes = document . body . childNodes ;
1111
12+ if ( childNodes . length === 0 ) {
13+ null
14+ }
15+
1216 if ( childNodes . length > 1 && allTextNodes ( childNodes ) ) {
1317 if ( process . env . NODE_ENV === 'development' ) {
1418 console . debug ( "[JSONViewer] Loaded from a multiple text nodes, normalizing" ) ;
@@ -17,26 +21,25 @@ function getPreWithSource() {
1721 document . body . normalize ( ) // concatenates adjacent text nodes
1822 }
1923
20- if ( childNodes . length === 1 ) {
21- var childNode = childNodes [ 0 ] ;
22- var nodeName = childNode . nodeName
23- var textContent = childNode . textContent
24-
25- if ( nodeName === "PRE" ) {
26- return childNode ;
27-
28- // if Content-Type is text/html
29- } else if ( nodeName === "#text" && textContent . trim ( ) . length > 0 ) {
30- if ( process . env . NODE_ENV === 'development' ) {
31- console . debug ( "[JSONViewer] Loaded from a text node, this might have returned content-type: text/html" ) ;
32- }
33-
34- var pre = document . createElement ( "pre" ) ;
35- pre . textContent = textContent ;
36- document . body . removeChild ( childNode ) ;
37- document . body . appendChild ( pre ) ;
38- return pre ;
24+ var childNode = childNodes [ 0 ] ;
25+ var nodeName = childNode . nodeName
26+ var textContent = childNode . textContent
27+
28+ if ( nodeName === "PRE" ) {
29+ return childNode ;
30+ }
31+
32+ // if Content-Type is text/html
33+ if ( nodeName === "#text" && textContent . trim ( ) . length > 0 ) {
34+ if ( process . env . NODE_ENV === 'development' ) {
35+ console . debug ( "[JSONViewer] Loaded from a text node, this might have returned content-type: text/html" ) ;
3936 }
37+
38+ var pre = document . createElement ( "pre" ) ;
39+ pre . textContent = textContent ;
40+ document . body . removeChild ( childNode ) ;
41+ document . body . appendChild ( pre ) ;
42+ return pre ;
4043 }
4144
4245 return null
0 commit comments