Skip to content

Commit

Permalink
Fix style injection, move to prod
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Aug 15, 2024
1 parent 706cdbb commit 00d9a39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions content/demo-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@
display: none;
}
`;
var styleSheet = document.createElement("style");
const loader = document.getElementById('loader');
styleSheet.textContent = styles;

for (const codeEl of document.querySelectorAll('code[data-run]')) {
const styleSheet = document.createElement("style");
styleSheet.textContent = styles;
const iframe = document.createElement('iframe');
const code = codeEl.textContent;
// find indent
Expand Down
14 changes: 7 additions & 7 deletions content/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@
display: none;
}
`;
var styleSheet = document.createElement("style");
const loader = document.getElementById('loader');
styleSheet.textContent = styles;

for (const codeEl of document.querySelectorAll('code[data-run]')) {
const styleSheet = document.createElement("style");
styleSheet.textContent = styles;
const iframe = document.createElement('iframe');
const code = codeEl.textContent;
// find indent
Expand All @@ -101,20 +101,21 @@
break;
}
let cleanCode = '';
let codeLines = '';
let blocks = [];
for (const line of code.split('\n')) {
if (cleanCode === '' && line.length === 0) {
continue
}
cleanCode += line.substring(indent) + '\n';
codeLines += '&code=' + line.substring(indent);
}
codeEl.textContent = cleanCode;
iframe.src = `https://quansight.github.io/jupyterlite-demo/repl/index.html?kernel=python&toolbar=1&${codeLines}`;
iframe.src = `https://quansight.github.io/jupyterlite-demo/repl/index.html?kernel=python&toolbar=1&code=${encodeURIComponent(cleanCode)}`;
iframe.style.width = '100%';
iframe.style.height = '300px';
iframe.onload = () => {
iframe.contentDocument.head.appendChild(styleSheet);
if (iframe.contentDocument) {
iframe.contentDocument.head.appendChild(styleSheet);
}
codeEl.replaceWith(iframe);
}
loader.appendChild(iframe);
Expand All @@ -123,4 +124,3 @@
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>

0 comments on commit 00d9a39

Please sign in to comment.