Skip to content

Instantly share code, notes, and snippets.

@robdodson
Created October 3, 2013 16:38
Show Gist options
  • Save robdodson/6812880 to your computer and use it in GitHub Desktop.
Save robdodson/6812880 to your computer and use it in GitHub Desktop.
Happy Polymer
<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