Lykos Lykos -4 years ago 220
Markdown Question

Rails & SimpleMDE - content displays indented

I've installed SimpleMDE on my rails app on a textarea for creating posts. The issue I have is when I want to edit the content of the post.body (ie the textarea that has the simplemde) looks indented like you see on the screenshot:

enter image description here

I have viewed the source code on show action in case it generates some extra tags, but the markdown looks fine

enter image description here

which makes me think that its something wrong with the editor. How can I fix this indentation that shows on the editor?

Here is also my code

# The gemfile
gem 'simplemde', '~> 0.1.0'
gem 'redcarpet', '~> 3.4'
# gem 'html-pipeline', '~> 2.5'
# gem 'github-markdown', '~> 0.6.9'
# gem 'sanitize', '~> 4.4'

# the _form.html.haml file
= f.input :body, as: :text, input_html: { class: 'simplemde' }

# the coffescript file
simplemde = null
$(document).on 'turbolinks:before-visit', ->
if simplemde?
simplemde.toTextArea()
simplemde = null

$(document).on 'turbolinks:load', ->
simplemde = new SimpleMDE(element: $('.simplemde')[0])

Answer Source

I have found a solution, so I'm going to post it here just in case anyone else needs it.

https://github.com/NextStepWebs/simplemde-markdown-editor/issues/480

Basically all needed todo was to replace

= f.input :body

with

~ f.input :body # notice the tilde symbol

and this would fix everything.

However if there's a much better solution, I'd appreciate if someone would post it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download