@@ -21,7 +21,6 @@ module.exports = function(node) {
2121 render ( node , docObject ) ;
2222
2323 var iframe = node . getElementsByTagName ( "iframe" ) [ 0 ] ;
24-
2524 iframe . addEventListener ( "load" , process ) ;
2625
2726 function process ( ) {
@@ -31,12 +30,15 @@ module.exports = function(node) {
3130 var html = getHTML . call ( this , demoEl ) ;
3231 var js = getJS . call ( this , sourceEl ) ;
3332
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 ) ;
3636
3737 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+
4042 show ( node . querySelector ( "[data-tab=js]" ) ) ;
4143 }
4244
@@ -50,18 +52,26 @@ module.exports = function(node) {
5052 if ( ! html ) {
5153 // try to make from body
5254 var clonedBody = this . contentDocument . body . cloneNode ( true ) ;
55+
5356 var scripts = [ ] . slice . call ( clonedBody . getElementsByTagName ( "script" ) ) ;
5457 scripts . forEach ( function ( script ) {
5558 if ( ! script . type || script . type . indexOf ( "javascript" ) === - 1 ) {
5659 script . parentNode . removeChild ( script ) ;
5760 }
5861 } ) ;
62+
5963 var styles = [ ] . slice . call ( clonedBody . getElementsByTagName ( "style" ) ) ;
6064 styles . forEach ( function ( style ) {
6165 style . parentNode . removeChild ( style ) ;
6266 } ) ;
67+
6368 html = clonedBody . innerHTML ;
6469 }
70+
71+ if ( html [ 0 ] === '\n' ) {
72+ html = html . slice ( 1 ) ;
73+ }
74+
6575 return html ;
6676 }
6777
@@ -128,10 +138,19 @@ module.exports = function(node) {
128138 }
129139 }
130140
131- function prettyify ( txt ) {
141+ function escape ( txt ) {
132142 txt = txt . replace ( / < / g, "<" ) ;
133- return typeof prettyPrintOne !== "undefined" ? prettyPrintOne ( txt ) : txt ;
143+ return txt ;
134144 }
145+
146+ function prettify ( el ) {
147+ if ( typeof Prism === "undefined" ) {
148+ return ;
149+ }
150+
151+ Prism . highlightElement ( el ) ;
152+ }
153+
135154 // Given the content height and the compute styles of the element,
136155 // compute the total height of the box
137156 function getTotalHeight ( height , computed ) {
0 commit comments