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 text = editor.firstChild.firstChild.firstChild;
window.getSelection().collapse(text, text.length);
document.execCommand("insertParagraph", false);
}, 100);
}, { once: true });
editor.addEventListener("input", () => {
pre.textContent = editor.innerHTML;
});