Last active
August 29, 2015 14:14
-
-
Save plwalters/e4639f2baffde0ac35d9 to your computer and use it in GitHub Desktop.
aurelia/markdown-component
This file contains hidden or 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
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