Skip to content

Instantly share code, notes, and snippets.

@nestarz
Last active June 4, 2020 15:54
Show Gist options
  • Save nestarz/19bd061744f3e839b0866d83ad24c50c to your computer and use it in GitHub Desktop.
Save nestarz/19bd061744f3e839b0866d83ad24c50c to your computer and use it in GitHub Desktop.
Markdown + Latex Editor/Renderer
<link rel="stylesheet" href="https://unpkg.com/latex.css/style.min.css" />
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
body > * {
height: 100%;
outline: none;
border: none;
}
.hidden {
visibility: hidden; /* display: none; remove history of textarea */
height: 0;
}
textarea.hidden {
margin-top: -10rem;
}
</style>
<article tabindex="0"></article>
<textarea tabindex="0" class="hidden"></textarea>
<script>
const $ = (tag) => document.querySelector(tag);
$("textarea").value = localStorage.getItem("content");
$("textarea").addEventListener("blur", () => {
$("textarea").classList.toggle("hidden");
$("article").classList.toggle("hidden");
$("article").innerHTML = marked($("textarea").value);
localStorage.setItem("content", $("textarea").value);
});
$("article").addEventListener("focus", () => {
$("textarea").classList.toggle("hidden");
$("article").classList.toggle("hidden");
$("textarea").focus();
});
$("article").focus();
$("textarea").blur();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment