Skip to content

Instantly share code, notes, and snippets.

@wernsey
Created April 18, 2019 11:45
Show Gist options
  • Save wernsey/0e7e13bd5b8048578bb2aa2b9cf02ab7 to your computer and use it in GitHub Desktop.
Save wernsey/0e7e13bd5b8048578bb2aa2b9cf02ab7 to your computer and use it in GitHub Desktop.
In browser Markdown editor
<html>
<head>
<title>Markdown Editor</title>
<!--
It uses showdownjs to render the Markdown https://github.com/showdownjs/showdown
-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.0/showdown.min.js"></script>
<style>
.fade{color:#E8E4D9;}
.highlight{color:#465DA6;background-color:#E8E4D9;}
a#toc-button:hover{color:#E8E4D9;background:#A88C3F;}
a#toc-button{color:#465DA6;background:#E8E4D9;cursor:pointer;font-size:small;padding: 0.3em 0.5em 0.5em 0.5em;font-family:monospace;border-radius:3px;}
a.footnote-back{text-decoration:initial;font-size:x-small;}
a.footnote{font-size:smaller;text-decoration:initial;}
a.top{font-size:x-small;text-decoration:initial;float:right;}
a:active{color:#A88C3F;}
a:hover{color:#A88C3F;}
a:visited{color:#465DA6;}
abbr{cursor:help;}
a{color:#465DA6;}
blockquote{margin-left:1em;color:#465DA6;border-left:0.2em solid #6676A8;padding:0.25em 0.5em;}
body{color:#314070;font-family:Calibri,sans-serif;font-size:11pt;line-height:1.5em;padding:1em 2em;width:80%;margin:0 auto;min-height:100%;float:none;}
caption{padding:0.5em;font-style:italic;}
code{color:#465DA6;}
dd{padding:0.3em;}
del,s{color:#A88C3F;}
div#table-of-contents{padding:0;font-size:smaller;}
div{padding:0.5em;}
dl{margin:0.5em;}
dt{font-weight:bold;}
h1,h2,h3,h4,h5,h6{font-weight:normal;line-height:1.2em;}
h1{color:#314070;border-bottom:1px solid #314070;padding:0.3em 0.1em;}
h2{color:#465DA6;border-bottom:1px solid #465DA6;padding:0.2em 0.1em;}
h3{color:#6676A8;border-bottom:1px solid #6676A8;padding:0.1em 0.1em;}
h4,h5,h6{color:#A88C3F;padding:0.1em 0.1em;}
h4{border-bottom:1px solid #A88C3F}
hr{background:;height:1px;border:0;}
mark{color:#465DA6;background-color:#E8E4D9;}
ol.footnotes{font-size:small;color:#A88C3F}
pre{color:#465DA6;background:#E8E4D9;border:1px solid;border-radius:2px;line-height:1.25em;margin:0.25em 0.5em;padding:0.75em;overflow-x:auto;}
p{margin:0.5em 0.1em;}
strong,b{color:#314070}
table{border-collapse:collapse;margin:0.5em;}
th,td{padding:0.5em 0.75em;border:1px solid #A88C3F;}
th{color:#465DA6;border:1px solid #6676A8;border-bottom:2px solid #6676A8;}
tr:nth-child(odd){background-color:#E8E4D9;}
.column {
float: left;
width: 47%;
margin:1vw;
box-sizing: border-box;
height:90vh;
max-height:90vh;
border: 1px solid gray;
}
.row:after {
content:"";
display:table;
clear:both;
}
.left {
padding:0px;
}
.right {
padding:1em;
overflow:auto;
}
#preview {
overflow:auto;
}
#text-input {
resize:none;
border:none;
width:100%;
height:100%;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="row">
<div class="column left">
<textarea id="text-input" oninput="this.editor.update()" placeholder="Type Markdown here..."></textarea>
</div>
<div class="column right">
<div id="preview">Markdown preview</div>
</div>
</div>
<div></div>
<script>
function Editor(input, preview) {
let options = {strikethrough: true, tasklists : true, literalMidWordUnderscores : true };
let converter = new showdown.Converter(options);
this.update = function () {
preview.innerHTML = converter.makeHtml(input.value);
};
input.editor = this;
this.update();
}
var $ = function (id) { return document.getElementById(id); };
new Editor($("text-input"), $("preview"));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment