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 11var scriptRegExp = / < s c r i p t \s ( [ ^ > ] + ) > ( [ \s \S ] * ?) < \/ s c r i p t > / ig;
22var 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;
34var templateRegExp = / < t e m p l a t e \s ? ( [ ^ > ] + ) ? > ( [ \s \S ] * ?) < \/ t e m p l a t e > / ig;
45var moduleTest = / t y p e = [ " ' ] ( [ \w \/ ] + ) [ " ' ] / ;
56var srcTest = / s r c = / ;
@@ -22,12 +23,18 @@ var types = {
2223 // It doesn't have a src, so we assume this has a body
2324 else if ( matchTest ) {
2425 HTML = HTML . replace ( match , "" ) . trim ( ) ;
25- var CSS ;
26+ var CSS , PRECSS ;
2627 var styleResults = HTMLwithoutTemplates . match ( styleRegExp ) ;
2728 if ( styleResults ) {
2829 HTML = HTML . replace ( styleResults [ 0 ] , "" ) . trim ( ) ;
2930 CSS = styleResults [ 1 ] . trim ( ) ;
3031 }
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+ }
3138 if ( types [ matchTest [ 1 ] ] ) {
3239 result = types [ matchTest [ 1 ] ] ( code . trim ( ) ) ;
3340 } else {
@@ -39,6 +46,10 @@ var types = {
3946 }
4047 if ( CSS ) {
4148 result . css = CSS ;
49+
50+ if ( PRECSS ) {
51+ result . css_pre_processor = PRECSS ;
52+ }
4253 }
4354 }
4455 } ) ;
Original file line number Diff line number Diff line change @@ -115,6 +115,22 @@ describe("bit-docs-html-codepen-link", function() {
115115 assert . equal ( data . js_pre_processor , 'babel' ) ;
116116 } ) ;
117117
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+
118134 it . skip ( "is able to create external js" , function ( ) {
119135 var data = codepenData . html ( `
120136 <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