jbowens / jBBCode

A lightweight but extensible BBCode parser
http://jbbcode.com
MIT License
164 stars 32 forks source link

Unparse function #32

Closed nokimaro closed 9 years ago

nokimaro commented 9 years ago

What about to create unparse method to replace html-tag pairs from "Code Definition Set" to BB-codes? For example I'am parsing text to html before saving it to DB. If i want to edit saved text, i need to store 2 versions of text in DB - parsed (getAsHtml()) and unparsed (getAsBBCode())

jbowens commented 9 years ago

You should store the raw text/bbcode in your database, not the html.

nokimaro commented 9 years ago

I understand this. But if i don't want to parse text every time before output? Anyway here dirty hack to unparse tags with preg_replace() https://gist.github.com/nokimaro/a6fd94481983562f2b5c

jbowens commented 9 years ago

If the bbcode you're parsing is large/complex enough to warrant it, you could cache the html version. You could store it in the database, memcached, or some other data store. In general, the raw bbcode should be your authoritative copy. You may change the html output for bbcode tags in the future. If you don't store the bbcode, you'll have inconsistent renderings of bbcode.