Skip to content

Commit

Permalink
fix: codepen js
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitskvmdam committed Sep 24, 2023
1 parent 5a2e7d0 commit c337d21
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tmpl/examples.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

data.forEach(function(example) {

var jsonString = JSON.stringify(example.code)
.replace(/"/g, """)
.replace(/'/g, "'");
if (example.caption) {
?>
<p class="code-caption"><?js= example.caption ?></p>
Expand All @@ -20,13 +17,23 @@
if(enable_for.findIndex(function (val) { return val === "examples"}) !== -1) {
var options = codepen.options || {};
var optionsString = '';
var optionsKey = Object.keys(options)

var code = `${options.js}
${example.code}
`

var jsonString = JSON.stringify(code)
.replace(/"/g, "&quot;")
.replace(/'/g, "&apos;");

var optionsKey = Object.keys(options).filter((key) => key !== 'js' )
optionsKey.map((key, idx) => {
optionsString += '"' + key +'": "' + options[key].replace(/"/g, "&quot;").replace(/'/g, "&apos;") + '"';
if(idx !== optionsKey.length - 1) {
optionsString += ','
}
})

?>
<form action="https://codepen.io/pen/define" method="POST" target="_blank" class="codepen-form">
<input type="hidden" name="data" value='{"title": "<?js= example.caption || 'Example' ?>", "js": <?js= jsonString ?>, <?js= optionsString ?> }' />
Expand Down

0 comments on commit c337d21

Please sign in to comment.