JSFiddle - React, Tailwind, and code Playground

HTML

<div id="editor" contenteditable><p><a href="foo">forcus this editor</a></p></div>
<pre id="source"></pre>

JavaScript

var editor = document.getElementById("editor");
var pre = document.getElementById("source");
try {
  document.execCommand("defaultParagraphSeparator", false, "p");
} catch (e) {}
editor.addEventListener("focus", () => {
  setTimeout(() => {
    let a = editor.firstChild.firstChild;
    window.getSelection().collapse(a, a.childNodes.length);
    document.execCommand("insertParagraph", false);
}, 100);
}, { once: true });
editor.addEventListener("input", () => {
  pre.textContent = editor.innerHTML;
});