Skip to content

Commit e2a8e53

Browse files
committed
fix inline config
1 parent 796b1c6 commit e2a8e53

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gitbook-plugin-jsfiddle",
33
"description": "JSFiddle Integration into GitBook",
44
"main": "index.js",
5-
"version": "1.0.0-alpha.5",
5+
"version": "1.0.0-alpha.6",
66
"author": {
77
"name": "Konstantin Krivlenia"
88
},

src/replace.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var htmlToDom = function (html) {
2929
var extractConfigFromURL = function (href) {
3030
var match = /(#)(.+)$/ig.exec(href);
3131
if (match && match[2]) {
32-
return match[2].split('&').reduce(function (params, param) {
32+
return match[2].split('&').reduce(function (params, param) {
3333
var splitParam = param.split('=');
3434
if (splitParam[0] === 'tabs') {
3535
splitParam[1] = splitParam[1].split(',');
@@ -50,7 +50,10 @@ var generateAdditionalParams = function (config) {
5050
return colors;
5151
}, '');
5252
colors = colors.replace(/&$/, '');
53-
return params + '?' + colors;
53+
if (colors) {
54+
return params + '?' + colors;
55+
}
56+
return params;
5457
};
5558

5659
var generateUrl = function (config) {
@@ -69,7 +72,7 @@ var creator = {
6972
' width=',
7073
'"' + (config.width ? config.width : '100%') + '"',
7174
' height=',
72-
'"' + (config.height ? config.height : '300px') + '"',
75+
'"' + (config.height ? config.height : '300') + '"',
7376
' src="' + generateUrl(config) + '"',
7477
' allowfullscreen="allowfullscreen" frameborder="0"',
7578
'>',

tests/replace.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ test('replacer', function (assert) {
3636
tabs: ['js', 'result']
3737
}),
3838
`<div>
39-
<iframe width="100%" height="300px" src="//jsfiddle.net/zalun/NmudS/embedded/js,result/dark/?bodyColor=red&accentColor=red" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
39+
<iframe width="100%" height="300" src="//jsfiddle.net/zalun/NmudS/embedded/js,result/dark/?bodyColor=red&accentColor=red" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
4040
</div>`.replace(/\s+/g, ' ')
4141
, 'replace on frame with params and dark theme');
4242
assert.equal(
4343
replace(
44-
'<div><a href="https://jsfiddle.net/09bv780j/#tabs=result,css&width=500px&type=script&theme=dark&bodyColor=blue"></a></div>',
44+
'<div><a href="https://jsfiddle.net/09bv780j/#tabs=result,css&amp;width=500px&amp;type=script&amp;theme=dark&amp;bodyColor=blue"></a></div>',
4545
{
46-
bodyColor:'red',
47-
type:'frame',
46+
bodyColor: 'red',
47+
type: 'frame',
4848
accentColor: 'red',
49-
tabs:['js']
49+
tabs: ['js']
5050
}
5151
),
5252
'<div><script async src="https://jsfiddle.net/09bv780j/embed/result,css/dark/?bodyColor=blue&accentColor=red"></script></div>',

0 commit comments

Comments
 (0)