Ionaru / easy-markdown-editor

EasyMDE: A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.
https://stackblitz.com/edit/easymde
MIT License
2.39k stars 316 forks source link

Setting Preview mode as the default mode. #142

Closed jvalrog closed 4 years ago

jvalrog commented 4 years ago

Hi everyone, amazing software you have here. I'm using it in a personal project for a note taking app and it's working perfectly.

My question is if the editor can be rendered, the first time I mean, in Preview mode by default.

Because I just want to view my notes as they are rendered, until I need to edit one of them. That's when I'd change to Edit mode.

Thanks.

jvalrog commented 4 years ago

Ok I solved it. I'll show how I made it for anyone in the future.

Just call togglePreview() after the easyMDE declaration in your HTML:

<textarea></textarea>
<script>
     var easyMDE = new EasyMDE({
         ..... options here
     });

     easyMDE.togglePreview();
</script>
KingDarBoja commented 4 years ago

@jvalrog Thank you! Was able to set the editor to preview by default on my Angular App by calling:

public ngAfterViewInit(): void {
    this.TdTextEditor.easyMDE.togglePreview();
}

Where TdTextEditor comes from:

@ViewChild(TdTextEditorComponent, { static: false }) public TdTextEditor: TdTextEditorComponent;

For anyone using Angular in the future.