File tree Expand file tree Collapse file tree 2 files changed +32
-12
lines changed Expand file tree Collapse file tree 2 files changed +32
-12
lines changed Original file line number Diff line number Diff line change 1
- var scriptRegExp = / < s c r i p t \s ( [ ^ > ] + ) > ( [ \s \S ] * ?) < \/ s c r i p t > / i ;
1
+ var scriptRegExp = / < s c r i p t \s ( [ ^ > ] + ) > ( [ \s \S ] * ?) < \/ s c r i p t > / ig ;
2
2
var styleRegExp = / < s t y l e > ( [ \s \S ] * ?) < \/ s t y l e > / i;
3
3
var moduleTest = / t y p e = [ " ' ] m o d u l e [ " ' ] / ;
4
+ var srcTest = / s r c = / ;
4
5
var types = {
5
6
html : function htmlType ( text ) {
6
- // test if a module script tag exists
7
- var results = text . match ( scriptRegExp ) ;
8
- if ( results ) {
9
- var attrs = results [ 1 ] ;
10
- if ( moduleTest . test ( attrs ) ) {
11
7
12
- var HTML = text . replace ( results [ 0 ] , "" ) . trim ( ) ;
8
+ var result ;
9
+
10
+ text . replace ( scriptRegExp , function ( match , attrs , code ) {
11
+
12
+ if ( moduleTest . test ( attrs ) && ! srcTest . test ( attrs ) ) {
13
+
14
+ var HTML = text . replace ( match , "" ) . trim ( ) ;
13
15
14
16
var styleResults = HTML . match ( styleRegExp ) ;
15
17
if ( styleResults ) {
16
18
HTML = HTML . replace ( styleResults [ 0 ] , "" ) . trim ( ) ;
17
- return {
19
+ result = {
18
20
html : HTML ,
19
- js : results [ 2 ] ,
21
+ js : code . trim ( ) ,
20
22
js_module : true ,
21
23
editors : "1011" ,
22
24
css : styleResults [ 1 ] . trim ( )
23
25
} ;
24
26
} else {
25
- return {
27
+ result = {
26
28
html : HTML ,
27
- js : results [ 2 ] ,
29
+ js : code . trim ( ) ,
28
30
js_module : true ,
29
31
editors : "1011"
30
32
} ;
31
33
}
32
34
33
35
34
36
}
35
- }
37
+ } ) ;
38
+ return result ;
36
39
} ,
37
40
js : function ( text ) {
38
41
return {
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ var assert = require("assert");
2
2
var generate = require ( "bit-docs-generate-html/generate" ) ;
3
3
var path = require ( "path" ) ;
4
4
var fs = require ( "fs" ) ;
5
+ var codepenData = require ( "./codepen-data" ) ;
5
6
6
7
var Browser = require ( "zombie" ) ;
7
8
var connect = require ( "connect" ) ;
@@ -74,4 +75,20 @@ describe("bit-docs-html-codepen-link", function() {
74
75
} , done ) ;
75
76
} , done ) ;
76
77
} ) ;
78
+
79
+ it ( "is able to ignore scripts with sources" , function ( ) {
80
+ var data = codepenData . html ( `
81
+ <mock-url></mock-url>
82
+ <bit-json-editor></bit-json-editor>
83
+ <script src="//unpkg.com/mock-url@^5.0.0" type="module"></script>
84
+ <script src="//unpkg.com/bit-json-editor@^5.0.0" type="module"></script>
85
+ <script type="module">
86
+ foo = "bar";
87
+ </script>
88
+ <style>
89
+ bit-json-editor { height: 200px; }
90
+ </style>
91
+ ` ) ;
92
+ assert . equal ( data . js , 'foo = "bar";' )
93
+ } ) ;
77
94
} ) ;
You can’t perform that action at this time.
0 commit comments