Add version check

This commit is contained in:
yuin 2024-02-10 19:35:14 +09:00
parent c6f5127385
commit 568c4f75d9
4 changed files with 34 additions and 5 deletions

View file

@ -56,7 +56,9 @@
const previewElm = $('preview');
const htmlElm= $$('#html pre');
const permelinkElm = $('permalink')
const messageElm = $('message');
messageElm.innerText = "";
const options = getOptions();
const html = toHtml(inputElm.value, options);
previewElm.innerHTML = html;
@ -84,13 +86,20 @@
const onload = function(obj) {
wasm = obj.instance;
go.run(wasm);
document.getElementById("convert-markdown").disabled = false;
$("convert-markdown").disabled = false;
const u = new URL(location.href);
if(u.searchParams.has("m")) {
setOptions(u.searchParams.get("o"));
$("input").value = decodeURIComponent(u.searchParams.get("m"));
convert();
}
if(u.searchParams.has("v")) {
const v = u.searchParams.get("v")
if(v !== goldmarkVersion) {
$("message").innerHTML = "<div class=\"warn\">This link was created for goldmark@"+v+". Results may differ with this version.</div>";
}
}
};
if ('instantiateStreaming' in WebAssembly) {
@ -101,8 +110,7 @@
).then(bytes => WebAssembly.instantiate(bytes, go.importObject).then(onload));
}
[...document.querySelectorAll('#container pre')]
.map(pre => {
for(const pre of [...document.querySelectorAll('#container pre')]){
const button = document.createElement('button');
pre.parentNode.insertBefore(button, pre);
button.textContent = 'copy';
@ -121,7 +129,7 @@
button.textContent = 'copy';
}, 500);
});
});
}
});
@ -130,6 +138,8 @@
<body>
<h1>goldmark@v1.7.0 playground</h1>
<section id="message">
</section>
<div id="container">
<div id="markdown">
<div>

View file

@ -1148,3 +1148,7 @@ button.pre-copy {
font-size: .8em;
cursor: pointer;
}
#message .warn {
color: var(--color-danger-fg);
}

View file

@ -56,7 +56,9 @@
const previewElm = $('preview');
const htmlElm= $$('#html pre');
const permelinkElm = $('permalink')
const messageElm = $('message');
messageElm.innerText = "";
const options = getOptions();
const html = toHtml(inputElm.value, options);
previewElm.innerHTML = html;
@ -84,13 +86,20 @@
const onload = function(obj) {
wasm = obj.instance;
go.run(wasm);
document.getElementById("convert-markdown").disabled = false;
$("convert-markdown").disabled = false;
const u = new URL(location.href);
if(u.searchParams.has("m")) {
setOptions(u.searchParams.get("o"));
$("input").value = decodeURIComponent(u.searchParams.get("m"));
convert();
}
if(u.searchParams.has("v")) {
const v = u.searchParams.get("v")
if(v !== goldmarkVersion) {
$("message").innerHTML = "<div class=\"warn\">This link was created for goldmark@"+v+". Results may differ with this version.</div>";
}
}
};
if ('instantiateStreaming' in WebAssembly) {
@ -129,6 +138,8 @@
<body>
<h1>goldmark@{{version}} playground</h1>
<section id="message">
</section>
<div id="container">
<div id="markdown">
<div>

View file

@ -1148,3 +1148,7 @@ button.pre-copy {
font-size: .8em;
cursor: pointer;
}
#message .warn {
color: var(--color-danger-fg);
}