fix(playground): work around lack of module support in mdbook

This commit is contained in:
Amaan Qureshi 2025-01-22 04:04:49 -05:00
parent 79244b5815
commit 3e72969ce4
3 changed files with 12 additions and 12 deletions

View file

@ -90,10 +90,11 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.19.0/clusterize.min.js"></script>
<script>LANGUAGE_BASE_URL = "";</script>
<script type="module" src=playground.js></script>
<script type="module" src="playground.js"></script>
<script type="module">
import {initializePlayground} from './playground.js';
setTimeout(() => initializePlayground({local: true}), 1)
import * as TreeSitter from './tree-sitter.js';
window.TreeSitter = TreeSitter;
setTimeout(() => window.initializePlayground({local: true}), 1)
</script>
<style>

View file

@ -101,11 +101,10 @@ you must use at least one capture, like <code>(node_name) @capture-name</code></
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.min.js"></script>
<script>LANGUAGE_BASE_URL = "https://tree-sitter.github.io";</script>
<script src="https://tree-sitter.github.io/tree-sitter.js"></script>
<script type="module">
import * as TreeSitter from 'https://tree-sitter.github.io/tree-sitter.js';
window.TreeSitter = TreeSitter;
setTimeout(() => window.initializePlayground({local: false}), 1);
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.19.0/clusterize.min.js"></script>
<script>
setTimeout(() => {
window.initializePlayground({local: false})
}, 1)
</script>

View file

@ -1,5 +1,3 @@
import { Parser, Language } from './tree-sitter.js';
function initializeLocalTheme() {
const themeToggle = document.getElementById('theme-toggle');
if (!themeToggle) return;
@ -62,7 +60,9 @@ function initializeCustomSelect({ initialValue = null, addListeners = false }) {
}
}
export async function initializePlayground(opts) {
window.initializePlayground = async (opts) => {
const { Parser, Language } = window.TreeSitter;
const { local } = opts;
if (local) {
initializeLocalTheme();