@@ -21,7 +21,6 @@ module.exports = function(node) {
21
21
render ( node , docObject ) ;
22
22
23
23
var iframe = node . getElementsByTagName ( "iframe" ) [ 0 ] ;
24
-
25
24
iframe . addEventListener ( "load" , process ) ;
26
25
27
26
function process ( ) {
@@ -31,12 +30,15 @@ module.exports = function(node) {
31
30
var html = getHTML . call ( this , demoEl ) ;
32
31
var js = getJS . call ( this , sourceEl ) ;
33
32
34
- var dataForHtml = node . querySelector ( "[data-for=html] > pre" ) ;
35
- dataForHtml . innerHTML = prettyify ( html ) ;
33
+ var dataForHtml = node . querySelector ( "[data-for=html] > pre code, [data-for=html] > div > pre code" ) ;
34
+ dataForHtml . innerHTML = escape ( html ) ;
35
+ prettify ( dataForHtml ) ;
36
36
37
37
if ( js ) {
38
- var dataForJS = node . querySelector ( "[data-for=js] > pre" ) ;
39
- dataForJS . innerHTML = prettyify ( js . replace ( / \t / g, " " ) ) ;
38
+ var dataForJS = node . querySelector ( "[data-for=js] > pre code, [data-for=js] > div > pre code" ) ;
39
+ dataForJS . innerHTML = escape ( js ) ;
40
+ prettify ( dataForJS ) ;
41
+
40
42
show ( node . querySelector ( "[data-tab=js]" ) ) ;
41
43
}
42
44
@@ -50,18 +52,26 @@ module.exports = function(node) {
50
52
if ( ! html ) {
51
53
// try to make from body
52
54
var clonedBody = this . contentDocument . body . cloneNode ( true ) ;
55
+
53
56
var scripts = [ ] . slice . call ( clonedBody . getElementsByTagName ( "script" ) ) ;
54
57
scripts . forEach ( function ( script ) {
55
58
if ( ! script . type || script . type . indexOf ( "javascript" ) === - 1 ) {
56
59
script . parentNode . removeChild ( script ) ;
57
60
}
58
61
} ) ;
62
+
59
63
var styles = [ ] . slice . call ( clonedBody . getElementsByTagName ( "style" ) ) ;
60
64
styles . forEach ( function ( style ) {
61
65
style . parentNode . removeChild ( style ) ;
62
66
} ) ;
67
+
63
68
html = clonedBody . innerHTML ;
64
69
}
70
+
71
+ if ( html [ 0 ] === '\n' ) {
72
+ html = html . slice ( 1 ) ;
73
+ }
74
+
65
75
return html ;
66
76
}
67
77
@@ -128,10 +138,19 @@ module.exports = function(node) {
128
138
}
129
139
}
130
140
131
- function prettyify ( txt ) {
141
+ function escape ( txt ) {
132
142
txt = txt . replace ( / < / g, "<" ) ;
133
- return typeof prettyPrintOne !== "undefined" ? prettyPrintOne ( txt ) : txt ;
143
+ return txt ;
134
144
}
145
+
146
+ function prettify ( el ) {
147
+ if ( typeof Prism === "undefined" ) {
148
+ return ;
149
+ }
150
+
151
+ Prism . highlightElement ( el ) ;
152
+ }
153
+
135
154
// Given the content height and the compute styles of the element,
136
155
// compute the total height of the box
137
156
function getTotalHeight ( height , computed ) {
0 commit comments