Skip to content

Instantly share code, notes, and snippets.

@plwalters
Last active August 29, 2015 14:14
Show Gist options
  • Save plwalters/e4639f2baffde0ac35d9 to your computer and use it in GitHub Desktop.
Save plwalters/e4639f2baffde0ac35d9 to your computer and use it in GitHub Desktop.
aurelia/markdown-component
import {Behavior} from 'aurelia-framework';
import showdown from 'showdown';
import prism from 'prism';
//import 'prism/themes/prism-okaidia.css!';
export class MarkdownComponentAttachedBehavior {
static metadata(){
return Behavior
.attachedBehavior('markdown-component')
.withProperty('value', 'valueChanged', 'markdown-component');
}
static inject() { return [Element]; }
constructor(element) {
this.element = element;
// An instance of the converter
this.converter = new showdown.converter();
}
valueChanged(newValue){
this.element.innerHTML = this.converter.makeHtml(
newValue.value.split('\n').map((line) => line.trim()).join('\n')
);
prism.highlightAll(this.element.querySelectorAll('code'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment