Skip to content

Commit f7ebf9a

Browse files
author
Chasen Le Hara
committed
Fix POSTing data to CodePen & the editor view settings for <script type="module">
1 parent 291f2a6 commit f7ebf9a

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,15 @@ function cleanCodePenData(data) {
1717

1818
function createCodePen(data) {
1919

20-
var JSONstring =
21-
JSON.stringify(data)
22-
// Quotes will screw up the JSON
23-
.replace(/"/g, "&​quot;") // careful copy and pasting, I had to use a zero-width space here to get markdown to post this.
24-
.replace(/'/g, "&apos;");
25-
20+
var JSONstring = JSON.stringify(data);
2621

2722
var form = '<form action="https://codepen.io/pen/define" method="POST" target="_blank">' +
28-
'<input type="hidden" name="data" value=\'' +
29-
JSONstring +
30-
'\'>' +
23+
'<input type="hidden" name="data">' +
3124
'</form>';
3225

3326
var div = document.createElement("div");
3427
div.innerHTML = form;
28+
div.firstChild.firstChild.value = JSONstring;
3529
document.body.appendChild(div);
3630
div.firstChild.submit();
3731
setTimeout(function(){
@@ -123,6 +117,7 @@ module.exports = function() {
123117
var jsAsModule = "<script type=\"module\">\n" + data.js + "\n</script>";
124118
data.html = data.html ? data.html + "\n\n" + jsAsModule : jsAsModule;
125119
data.js = "";
120+
data.editors = "1001";// HTML, Result, & Console
126121
}
127122
if(data) {
128123
cleanCodePenData(data);

test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ describe("bit-docs-html-codepen-link", function() {
6363
html: '<my-app></my-app>\n\n<script type="module">\nimport { Component } from "//unpkg.com/can@^5.0.0-pre.1/core.mjs";\nComponent\n</script>',
6464
js: '',
6565
js_module: true,
66-
editors: '1011',
66+
editors: '1001',
6767
css: 'my-app {color: "green";}'
6868
},
6969
{
7070
html: '<script type="module">\nimport {DefineMap} from "//unpkg.com/can@^5.0.0-pre.1/core.mjs";\nconsole.log( myCounter.count ) //-> 1\n</script>',
7171
js: '',
7272
js_module: true,
73-
editors: '0011'
73+
editors: '1001'
7474
}
7575
]);
7676

0 commit comments

Comments
 (0)