Skip to content

Commit de5fadd

Browse files
committed
rough cut of trying to get external resources
1 parent 0af5e42 commit de5fadd

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

codepen-data.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ var types = {
66
html: function htmlType(text) {
77

88
var result;
9+
var HTML = text;
910

1011
text.replace(scriptRegExp, function(match, attrs, code) {
1112

1213
var matchTest = attrs.match(moduleTest);
1314

14-
if (matchTest && !srcTest.test(attrs)) {
15+
// This has a src="". We look for codepen-external
16+
if(srcTest.test(attrs)) {
1517

16-
var HTML = text.replace(match, "").trim();
18+
}
19+
// It doesn't have a src, so we assume this has a body
20+
else if (matchTest) {
21+
22+
HTML = HTML.replace(match, "").trim();
1723
var CSS;
1824
var styleResults = HTML.match(styleRegExp);
1925
if (styleResults) {

test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,18 @@ describe("bit-docs-html-codepen-link", function() {
114114
assert.equal(data.js.trim(), 'const element = <h1>Hello, world!</h1>;');
115115
assert.equal(data.js_pre_processor, 'babel');
116116
});
117+
118+
it("is able to create external js", function(){
119+
var data = codepenData.html(`
120+
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.2.1/rxjs.umd.js" codepen-external></script>
121+
<script src="https://foo.com" codepen-external></script>
122+
<script type="typescript">
123+
const {Observable} = rxjs;
124+
</script>
125+
`);
126+
assert.equal(data.js.trim(), 'const {Observable} = rxjs;');
127+
assert.equal(data.js_pre_processor, 'typescript');
128+
assert.equal(data.js_external,'https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.2.1/rxjs.umd.js;https://foo.com');
129+
assert.equal(data.html, undefined, "no html")
130+
});
117131
});

0 commit comments

Comments
 (0)