Quick demo on how to use Jade and CodeMirror to create a simple Jade editor with live preview.
xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jade Editor</title>
<link rel="stylesheet" href="codemirror.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<script src="codemirror.js"></script>
<script src="javascript.js"></script>
<script src="css.js"></script>
<script src="xml.js"></script>
<script src="htmlmixed.js"></script>
<script src="jade.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jade/1.11.0/jade.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js"></script>
<style>
html, body {
margin: 0;
height: 100%;
}
.CodeMirror {
border: solid 1px #aaa;
height: auto;
min-height: 300px;
}
.header {
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
padding: 10px 0;
border-bottom: solid 1px #0FA0CE;
margin-bottom: 10px;
}
.rendered-html {
background-color: #f5f5f5;
border: solid 1px #aaa;
min-height: 278px;
height: auto;
padding: 10px;
}
.rendered-html {
font-size: 14px;
font-family: 'Helvetica neue', Helvetica;
}
.rendered-html h1 {
font-size: 2.1rem;
font-weight: bold;
margin-bottom: 4px;
}
.rendered-html h2 {
font-size: 1.8rem;
font-weight: bold;
margin-bottom: 4px;
}
.rendered-html h3 {
font-size: 1.6rem;
font-weight: bold;
margin-bottom: 4px;
}
.rendered-html h4 {
font-size: 1.4rem;
font-weight: bold;
margin-bottom: 4px;
}
.lang-ref {
text-align: right;
text-transform: none;
}
.lang-ref a {
color: #aaa;
text-decoration: none;
margin-left: 10px;
}
.app-name {
color: #0FA0CE;
}
</style>
</head>
<body>
<div class="container header">
<div class="row">
<div class="eight columns">
<span class="app-name">jade live preview</span>
</div>
<div class="four columns lang-ref">
<a href="https://jade-lang.com/reference/" target="_blank">Jade Reference</a>
<a href="https://gist.github.com/pnavarrc/cdd92c979cdd5b548285" target="_blank">GitHub</a>
<a href="https://gist.github.com/pnavarrc/cdd92c979cdd5b548285#file-readme-md" target="_blank">About</a>
</div>
</div>
</div>
<div class="container jade-editor">
<div class="row">
<div class="six columns">
<textarea id="jade-source">
h1 Jade Live Preview
p A minimal editor with a live preview for
a(href="https://jade-lang.com/") Jade.
</textarea>
</div>
<div class="six columns">
<div id="rendered" class="rendered-html"></div>
</div>
</div>
</div>
<script>
var editorOptions = {
mode: {name: 'jade', alignCDATA: true},
lineNumbers: true,
tabSize: 2,
lineWrapping: true,
indentWithTabs: false
};
function updateRendered() {
var jadeSource = editor.getValue(),
jadeCompiled = jade.compile(jadeSource);
$('#rendered').html(jadeCompiled());
}
var editor = CodeMirror.fromTextArea($('#jade-source').get(0), editorOptions);
updateRendered();
editor.on('changes', updateRendered);
</script>
</body>
</html>
https://cdnjs.cloudflare.com/ajax/libs/jade/1.11.0/jade.min.js
https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js