File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1
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
+ var lessRegExp = / < s t y l e t y p e = " t e x t \/ l e s s " > ( [ \s \S ] * ?) < \/ s t y l e > / i;
3
4
var templateRegExp = / < t e m p l a t e \s ? ( [ ^ > ] + ) ? > ( [ \s \S ] * ?) < \/ t e m p l a t e > / ig;
4
5
var moduleTest = / t y p e = [ " ' ] ( [ \w \/ ] + ) [ " ' ] / ;
5
6
var srcTest = / s r c = / ;
@@ -22,12 +23,18 @@ var types = {
22
23
// It doesn't have a src, so we assume this has a body
23
24
else if ( matchTest ) {
24
25
HTML = HTML . replace ( match , "" ) . trim ( ) ;
25
- var CSS ;
26
+ var CSS , PRECSS ;
26
27
var styleResults = HTMLwithoutTemplates . match ( styleRegExp ) ;
27
28
if ( styleResults ) {
28
29
HTML = HTML . replace ( styleResults [ 0 ] , "" ) . trim ( ) ;
29
30
CSS = styleResults [ 1 ] . trim ( ) ;
30
31
}
32
+ var lessResults = HTMLwithoutTemplates . match ( lessRegExp ) ;
33
+ if ( lessResults ) {
34
+ HTML = HTML . replace ( lessResults [ 0 ] , "" ) . trim ( ) ;
35
+ CSS = lessResults [ 1 ] . trim ( ) ;
36
+ PRECSS = 'less' ;
37
+ }
31
38
if ( types [ matchTest [ 1 ] ] ) {
32
39
result = types [ matchTest [ 1 ] ] ( code . trim ( ) ) ;
33
40
} else {
@@ -39,6 +46,10 @@ var types = {
39
46
}
40
47
if ( CSS ) {
41
48
result . css = CSS ;
49
+
50
+ if ( PRECSS ) {
51
+ result . css_pre_processor = PRECSS ;
52
+ }
42
53
}
43
54
}
44
55
} ) ;
Original file line number Diff line number Diff line change @@ -115,6 +115,22 @@ describe("bit-docs-html-codepen-link", function() {
115
115
assert . equal ( data . js_pre_processor , 'babel' ) ;
116
116
} ) ;
117
117
118
+ it ( "is able to parse less in html" , function ( ) {
119
+ var data = codepenData . html ( `
120
+ <style type="text/less">
121
+ @custom-color: #454545;
122
+ </style>
123
+ <span>Hello.</span>
124
+ <script type="module">
125
+ function greeter(person) { return "Hello, " + person; }
126
+ </script>
127
+ ` ) ;
128
+ console . log ( JSON . stringify ( data ) ) ;
129
+ assert . equal ( data . css . trim ( ) , '@custom-color: #454545;' ) ;
130
+ assert . equal ( data . css_pre_processor , 'less' ) ;
131
+ } ) ;
132
+
133
+
118
134
it . skip ( "is able to create external js" , function ( ) {
119
135
var data = codepenData . html ( `
120
136
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.2.1/rxjs.umd.js" codepen-external></script>
You can’t perform that action at this time.
0 commit comments