简体   繁体   English

段落的文本区域

[英]Textarea to paragraphs

When I have to render textarea content to the front end I usually pass it thru a function that converts newlines to <br/> tags and double newlines signal paragraph tags so blocks of text get surrounded by <p> and </p> tags. 当我不得不将textarea内容呈现到前端时,我通常通过一个将换行符转换为<br/>标记的函数并将其传递给双行换行符来标记段落标记,以便文本块被<p></p>标记包围。

To save time I usually use a ready made PHP function from the wordpress codebase. 为了节省时间,我通常使用wordpress代码库中的现成PHP函数。 You can get the link from the man himself: http://ma.tt/scripts/autop/ 您可以从该人本人处获得链接: http : //ma.tt/scripts/autop/

If you check it out you'll see it does some heavy lifting with about 20 regular expressions. 如果您将其签出,将会看到它用大约20个正则表达式进行了一些繁重的工作。

I know I could use a wysiwyg editor (like TinyMCE or CKEditor) that can format the data on the client and then send it to the server (most of them add <p>..</p> tags by default) but I want to know the experience of others in handling raw textarea input and then displaying it on the front end. 我知道我可以使用所见即所得的编辑器(例如TinyMCE或CKEditor)来格式化客户端上的数据,然后将其发送到服务器(大多数情况下默认情况下添加<p>..</p>标签),但是我想要了解其他人在处理原始文本区域输入并将其显示在前端时的经验。

EDIT : Wow, was expecting more responses to this. 编辑 :哇,期待对此的更多答复。 Either most people use wysiwyg editors and/or direct output to browser and/or use basic functions like nl2br. 大多数人都使用所见即所得的编辑器和/或将输出直接输出到浏览器和/或使用基本功能(例如nl2br)。 I'll give this question another day. 我有一天再问这个问题。

If you check it out you'll see it does some heavy lifting with about 20 regular expressions. 如果您将其签出,将会看到它用大约20个正则表达式进行了一些繁重的工作。

I think you shouldn't be afraid of 20 regular expressions. 我认为您不应该害怕20个正则表达式。 They aren't demons of speed, but they aren't so slow in fact. 它们不是速度的魔鬼,但实际上并没有那么慢。 Most of sites converts content from some kind of BBCode/Textile/Markdown/others format to HTML just before displaying... and often they do this 20 times for a single page. 大多数网站在显示之前就将内容从某种BBCode / Textile / Markdown / others格式转换为HTML ...并且通常它们在单个页面上执行20次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM