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

Saving deletes newlines #226

Closed SebiBasti closed 4 years ago

SebiBasti commented 4 years ago

I'm trying to implement easyMDE in my little project. When I test it in the preview it works as intended:

raw input

Bildschirmfoto 2020-08-08 um 17 43 05

preview

Bildschirmfoto 2020-08-08 um 17 43 16

But when I submit it and then display it again it looks like this: Bildschirmfoto 2020-08-08 um 17 43 35

Somehow it gets rid of all the newlines and I can't figure out why. :-(

easyMDE for my input

<script>
    var easyMDE = new EasyMDE({
        element: document.getElementById("mde"),
        placeholder: "Write your post here...",
        autosave: {
            enabled: true,
            uniqueId: <%= current_user.id %>,
            delay: 10000,
        },
        renderingConfig: {
            codeSyntaxHighlighting: true
        },
        promptURLs: true,
        toolbar: ["bold", "italic", "strikethrough", "heading", "|", "code", "quote", "clean-block", "|", "link", "image", "|", "unordered-list", "ordered-list", "|", "preview", "side-by-side", "fullscreen", "|", "guide"]
    });
</script>

easyMDE for displaying content

<script>
    var easyMDE = new EasyMDE({
        element: document.getElementById("<%=j @id %>"),
        initialValue: "<%=j @content %>",
        renderingConfig: {
            codeSyntaxHighlighting: true
        },
        toolbar: false
    });
    easyMDE.togglePreview();
</script>
SebiBasti commented 4 years ago

I found the mistake. I was attaching easyMDE to a text field and not a text area (I'm using rails).

I changed <%= f.text_field :content, id: 'mde' %> to <%= f.text_area :content, id: 'mde' %>