Markdown as an option to string or text fields

(Epipheus) #1

Seems to me that markdown should perhaps be an option to a string or text field. Instead if I want a string that honors markdown, I get a super huge textbox.

(Aaron Russell) #2

This can be done too (I think). Most fields accept a :form_helper option. So you could try something like this:

field :my_text, :markdown, form_helper: :text_field

Bare in mind the markdown renderer will wrap a single line the value in <p /> tags .

(Epipheus) #3

Is there a way to control exactly what the markdown renderer does?

(Epipheus) #4

This didn’t work for me btw. Still resulted in a textarea.

(Aaron Russell) #5

Strange. I just tried it. It works for me… ?

Yes. Under the hood it’s using Redcarpet, The markdown field accepts a few relevant options: :renderer, :render_options and :extensions. Take a look at:

(Epipheus) #6

even restarted the server,etc. So you get a text field?

(Epipheus) #7

Can you try what happens when you leave off the form helper and them put it in?

(Epipheus) #8

any way to eliminate p-tags and just render what was typed?

(Aaron Russell) #9

@epipheus I’m not too sure what to say about the text_field as I can’t recreate and it works OK here. Could you perhaps try creating a new rails app with pushtype, generate a single node type and try setting the :form_helper option there.

If you can get it to work on a clean app, then at least we can say with some confidence there is something about your current app that is causing this - then we can try and explore why. It’s possible it’s a bug, but need to try and narrow it down first.

Regarding customising the makrdown output to not render <p>, I’m sure it’s possible by creating a custom Redcarpt renderer, but may be more hassle than it’s worth. Might be simpler to just use Rails’ sanitize method in your view to strip out paragraphs, or a regular expression.