JavaScript API

Read a selection and run commands from your own controls.

Code

<label class="editor-label" for="api-editor">Markdown</label>
<tint-editor id="api-editor" toolbar="none" rows="4" value="Select text to make it bold."></tint-editor>
<div class="actions">
  <button class="button" id="make-bold" type="button">Bold</button>
  <button class="button" id="insert-text" type="button">Insert signature</button>
</div>
<script type="module">
  const editor = document.querySelector("#api-editor");
  document.querySelector("#make-bold").addEventListener("click", () => editor.exec("bold"));
  document.querySelector("#insert-text").addEventListener("click", () => editor.insertText("\n\n— Sent from Tint"));
</script>

The code assumes the setup from the guide. Try the editor live in the interactive demos.