Script tag
Script tag
Load Tint with one script tag and save a draft from a plain HTML form.
Current Markdown source
Integration code
<script type="module" src="/site/demo.js"></script>
<form method="post" data-draft>
<label class="editor-label" for="draft">Markdown</label>
<tint-editor id="draft" name="body" required rows="7" value="# Field notes
Tint keeps your document as Markdown.
- Select text to format it.
- Save a draft and reload this page.
"></tint-editor>
<div class="row">
<button type="submit">Save draft</button>
<button type="reset">Reset</button>
</div>
<p class="hint" role="status"></p>
</form>Browser script
import "../tint-editor.js";
const form = document.querySelector("[data-draft]");
const editor = form.querySelector("tint-editor");
const status = form.querySelector('[role="status"]');
const key = "tint-demo-draft";
try {
const saved = localStorage.getItem(key);
if (saved !== null) {
editor.value = saved;
status.textContent = "Saved draft loaded.";
}
} catch {
status.textContent = "Browser storage is unavailable.";
}
form.addEventListener("submit", (event) => {
event.preventDefault();
const markdown = new FormData(form).get(editor.name);
try {
localStorage.setItem(key, markdown);
status.textContent = "Draft saved in this browser.";
} catch {
status.textContent = "Could not save the draft in this browser.";
}
});
form.addEventListener("reset", () => { status.textContent = "Editor reset."; });
editor.addEventListener("input", () => { status.textContent = ""; });The editor runs the code shown in the Code tab, with the setup from the guide. See generic examples for framework-free snippets. Open the standalone sample.