Skip to content

Commit 3ab8bbb

Browse files
authored
Merge pull request #6 from bit-docs/html-only
Work when there is HTML but no scripts
2 parents 5bd0813 + eeabd7a commit 3ab8bbb

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

codepen-data.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var scriptRegExp = /<script\s([^>]+)>([\s\S]*?)<\/script>/ig;
22
var styleRegExp = /<style>([\s\S]*?)<\/style>/i;
33
var moduleTest = /type=["']([\w\/]+)["']/;
44
var srcTest = /src=/;
5+
var DEFAULT_EDITORS = "0011";
6+
57
var types = {
68
html: function htmlType(text) {
79

@@ -40,27 +42,36 @@ var types = {
4042
}
4143
}
4244
});
45+
46+
// If there are no scripts the should at least be HTML
47+
if(!result) {
48+
result = {
49+
html: HTML,
50+
editors: DEFAULT_EDITORS
51+
}
52+
}
53+
4354
return result;
4455
},
4556
js: function(text) {
4657
return {
4758
js: text,
4859
js_module: true,
49-
editors: "0011"
60+
editors: DEFAULT_EDITORS
5061
};
5162
},
5263
typescript: function(text) {
5364
return {
5465
js: text,
5566
js_pre_processor: "typescript",
56-
editors: "0011"
67+
editors: DEFAULT_EDITORS
5768
};
5869
},
5970
jsx: function(text) {
6071
return {
6172
js: text,
6273
js_pre_processor: "babel",
63-
editors: "0011"
74+
editors: DEFAULT_EDITORS
6475
};
6576
}
6677
};

test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,13 @@ describe("bit-docs-html-codepen-link", function() {
128128
assert.equal(data.js_external,'https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.2.1/rxjs.umd.js;https://foo.com');
129129
assert.equal(data.html, undefined, "no html")
130130
});
131+
132+
it("works when there is no js", function() {
133+
var data = codepenData.html(`
134+
<div>Hello world</div>
135+
`)
136+
137+
assert(data, "got data");
138+
assert.equal(data.html.trim(), "<div>Hello world</div>");
139+
})
131140
});

0 commit comments

Comments
 (0)