Last active
September 25, 2019 21:20
-
-
Save gavinmcfarland/c6251ff28f4c93d12fd464b046f2ccea to your computer and use it in GitHub Desktop.
Experimenting with a Markdown component in Marko
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
| <Markdown># Hello ${input.name}</Markdown> |
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 marked from 'marked' | |
| class { | |
| onCreate() { | |
| this.state = { content: null }; | |
| } | |
| onInput() { | |
| this.state.content = null; | |
| } | |
| recalculate() { | |
| if (this.state.content === null) { | |
| this.state.content = marked(this.getEl("container").textContent); | |
| } | |
| } | |
| onMount() { | |
| this.recalculate(); | |
| } | |
| onUpdate() { | |
| this.recalculate(); | |
| } | |
| } | |
| <div.wrapper key="container" style={ | |
| visibility: state.content ? "unset" : "hidden" | |
| }> | |
| <if(state.content)>$!{state.content}</if> | |
| <else> | |
| <${input.renderBody}/> | |
| </else> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment