Handling more than one markup language in a text a

2019-08-15 20:40发布

I'd like to now how to handle multiple markup languages (textile, markdown and bbcode) in a text area using ruby on rails 3.

The user would be able to select the markup language he/she wants to use, write in that language, and then the view would render the text using the markup language selected by the user.

I'm currently handling that storing a field for each text area, but I'm sure there are better ways and I'd love to hear your opinions and come up with a better way.

1条回答
贪生不怕死
2楼-- · 2019-08-15 21:18

When are you processing the markup the user enters? Are they ever going to need to re-retrieve it?

I'd do this by having three attributes on my model: original_text, markup_language (which is either textile, markdown, or bbcode), and rendered_text. When the user hit save, I'd save the text and use the value they provided for markup_language to figure out what renderer to use to store it into rendered_text.

查看更多
登录 后发表回答