How to store lightweight formatting (Textile, Markdown) in database?
Asked Answered
T

4

19

I'm going to be implementing a lightweight formatting language (probably Textile, maybe Markdown) in a project I'm working on, and I'm wonder how best to store it in the database.

If the user is able to edit the content they're posting, it makes sense to me that the original, non-converted markup be stored so that the user doesn't have to edit HTML the next time around. But since the content is going to be displayed a whole lot more than edited, it also makes sense to store a converted copy of the content so that the original doesn't have to be sent through Textile on every page view.

So, is the common practice to store both the original and converted content side-by-side in the database? Is there a better way?

Thanks!

Tolan answered 29/1, 2009 at 17:7 Comment(0)
U
25

Store markdown:

  • Every view = conversion
  • Every edit = no processing

Store html

  • Every view = no processing
  • Every edit = convert to markdown and back

Store both

  • Every view = no processing
  • Every edit = convert to html after edit

You have to weigh up your processing costs vs. your storage cost.

Upstroke answered 29/1, 2009 at 17:12 Comment(0)
T
1

You should definetly store original Textile/Markdown markup and use either standard HTTP caching stuff (Last-modified, Expires-At, ETag) to cache rendered pages or just cache the result of processing markup.

Tacitus answered 29/1, 2009 at 17:9 Comment(0)
R
1

I'm currently using Markdown with PHP. I store the markdown-source in the database, and I display the Converted Version upon request. I have no performance issues, and am very happy with this setup.

Raulrausch answered 29/1, 2009 at 17:10 Comment(0)
P
1

What I've seen is indeed to store the compiled HTML in a seperate row in the database. Just have one row 'content' and another 'content_html', and save the compiled HTML in the 'content_html' row.

(Surely you have some kind of save method that you can override to do this?)

Platter answered 29/1, 2009 at 17:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.