File tree 3 files changed +52
-7
lines changed
3 files changed +52
-7
lines changed Original file line number Diff line number Diff line change @@ -31,15 +31,19 @@ module.exports = function(node) {
31
31
var js = getJS . call ( this , sourceEl ) ;
32
32
33
33
if ( html && html . trim ( ) ) {
34
- var dataForHtml = node . querySelector ( "[data-for=html] > pre code, [data-for=html] > div > pre code" ) ;
34
+ var htmlPre = node . querySelector ( '[data-for=html] > pre, [data-for=html] > div > pre' ) ;
35
+ var dataForHtml = document . createElement ( 'code' ) ;
36
+ htmlPre . appendChild ( dataForHtml ) ;
35
37
dataForHtml . innerHTML = escape ( html ) ;
36
38
prettify ( dataForHtml ) ;
37
39
38
40
show ( node . querySelector ( "[data-tab=html]" ) ) ;
39
41
}
40
42
41
43
if ( js ) {
42
- var dataForJS = node . querySelector ( "[data-for=js] > pre code, [data-for=js] > div > pre code" ) ;
44
+ var jsPre = node . querySelector ( '[data-for=js] > pre, [data-for=js] > div > pre' ) ;
45
+ var dataForJS = document . createElement ( 'code' ) ;
46
+ jsPre . appendChild ( dataForJS ) ;
43
47
dataForJS . innerHTML = escape ( js ) ;
44
48
prettify ( dataForJS ) ;
45
49
Original file line number Diff line number Diff line change 1
- // Note that the space in the <code> </code> blocks is significant:
2
- // without it, any demo in a page would break the rest of the code
3
- // examples throughout the page.
1
+ // Leaving the content the of the <pre> empty is significant
2
+ // <code> element will be appended when processing the code highlighting
3
+ // this prevent PrismJS to register "Copy" button for demos at bit-docs-prettify step
4
+
4
5
5
6
module . exports = `
6
7
<ul>
@@ -12,9 +13,9 @@ module.exports = `
12
13
<iframe></iframe>
13
14
</div>
14
15
<div class="tab-content" data-for="html">
15
- <pre class="line-numbers language-html"><code> </code>< /pre>
16
+ <pre class="line-numbers language-html"></pre>
16
17
</div>
17
18
<div class="tab-content" data-for="js">
18
- <pre class="line-numbers language-js"><code> </code>< /pre>
19
+ <pre class="line-numbers language-js"></pre>
19
20
</div>
20
21
` ;
Original file line number Diff line number Diff line change @@ -507,5 +507,45 @@ describe("bit-docs-tag-demo", function() {
507
507
} ) ;
508
508
} ) ;
509
509
} ) ;
510
+
511
+ describe ( "Insert code tag" , function ( ) {
512
+ insertCodeFor ( "html" ) ;
513
+ insertCodeFor ( "js" ) ;
514
+
515
+ function insertCodeFor ( htmlOrJs ) {
516
+ var tab = htmlOrJs === "html" ? "withoutJs" : "withoutHtml" ;
517
+ describe ( htmlOrJs , function ( ) {
518
+
519
+ before ( function ( ) {
520
+ return ctx . browser . newPage ( ) . then ( function ( p ) {
521
+ ctx . page = p ;
522
+ return ctx . page . goto (
523
+ "http://127.0.0.1:8081/test/temp/" + tab + ".html"
524
+ ) ;
525
+ } ) . then ( function ( ) {
526
+ return ctx . page . waitForFunction ( function ( ) {
527
+ return ! ! document . querySelector ( ".tab.active" ) ;
528
+ } ) ;
529
+ } ) ;
530
+ } ) ;
531
+
532
+ after ( function ( ) {
533
+ return ctx . page . close ( ) . then ( function ( ) {
534
+ ctx . page = null ;
535
+ } ) ;
536
+ } ) ;
537
+
538
+ it ( "inserts " + htmlOrJs + " code" , function ( ) {
539
+ return ctx . page . evaluate ( function ( htmlOrJs ) {
540
+ return {
541
+ code : document . querySelector ( "[data-for=" + htmlOrJs + "] > pre" ) ,
542
+ }
543
+ } , htmlOrJs ) . then ( function ( r ) {
544
+ assert . ok ( r . code , "Code inserted at the right spot" ) ;
545
+ } )
546
+ } ) ;
547
+ } ) ;
548
+ }
549
+ } ) ;
510
550
} ) ;
511
551
} ) ;
You can’t perform that action at this time.
0 commit comments