Created
October 3, 2013 16:38
-
-
Save robdodson/6812880 to your computer and use it in GitHub Desktop.
Happy Polymer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<polymer-element name="mark-down-editor"> | |
<template> | |
<style> | |
#markup, #markdown { | |
width: 50%; | |
float: left; | |
} | |
#editor { | |
width: 80%; | |
height: 250px; | |
} | |
</style> | |
<div id="markup"> | |
<textarea id="editor" on-keyup="render" value="{{ text }}"></textarea> | |
</div> | |
<div id="markdown"></div> | |
</template> | |
<script> | |
Polymer("mark-down-editor", { | |
created: function() { | |
this.text = this.trim(this.innerHTML); | |
this.render(); | |
}, | |
render: function() { | |
var parsed = markdown.toHTML(this.text); | |
this.$.markdown.innerHTML = parsed; | |
}, | |
// Thanks Ryan Seddon! (https://github.com/ryanseddon/markdown-component) | |
// Remove all leading/trailing whitespace so it's not confused as | |
// a code block | |
trim: function(str) { | |
var cleaned = str.split('\n').map(function(x) { | |
return x.trim(); | |
}).join('\n'); | |
return cleaned; | |
} | |
}); | |
</script> | |
</polymer-element> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment