在文本区域中处理多种标记语言

在文本区域中处理多种标记语言

本文介绍了在文本区域中处理多种标记语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在想如何在Rails 3上使用ruby处理文本区域中的多种标记语言(纺织品,降价和bbcode).

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.

推荐答案

何时处理用户输入的标记?他们是否需要重新检索它?

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

我将通过在模型上具有三个属性来做到这一点:original_textmarkup_language(可以是Textile,markdown或bbcode)和rendered_text.当用户单击保存"时,我将保存文本并使用为markup_language提供的值来确定使用哪个渲染器将其存储到rendered_text中.

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.

这篇关于在文本区域中处理多种标记语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:41