0

First, I am not using a WYSIWYG. The only modes of formatting will be like: *italic*, **bold**, #header#, [link](www.link.com), and maybe a couple others.

^ That being the case, when do I do the actual parsing? Before I store it in the database OR after I retrieve it from the database?

I would rather not do it before storage, but I'm unsure...

Greg
  • 23,155
  • 11
  • 57
  • 79
EliTheDawg
  • 1,157
  • 15
  • 36
  • 2
    1 vote to close it, guess my lowly rep of 375 doesn't allow me make a 'Parse HTML with Regex' joke. – EliTheDawg Apr 18 '11 at 18:47
  • 2
    Don't take it personally, I think someone just got a little trigger-happy. I thought it was pretty funny, although by your own admission it was inaccurate (re: "not really"). – Donut Apr 18 '11 at 18:52
  • No worries, I actually got a kick out of the vote to close it. Not to mention, it was a pretty weak joke... – EliTheDawg Apr 18 '11 at 18:55
  • 1
    Also, what you're trying to do sounds exactly like [Markdown](http://daringfireball.net/projects/markdown/), a flavor of which is used right here on SO. See [this question](http://stackoverflow.com/questions/2138024/why-do-i-need-markdown/2138059) for some good discussion relating to Markdown (especially the first answer). – Donut Apr 18 '11 at 18:55
  • 1
    Cool, I'll check it out - thanks Donut. Down with Greg – EliTheDawg Apr 18 '11 at 18:56

2 Answers2

3

After you've retrieved the text from the database. Parsing it before storing it means that you lose your "styling tags" and you or your users will be presented with the plain HTML code if you're retrieving it again for editing.

stlvc
  • 833
  • 5
  • 16
1

I would suggest it depends on the volume of content you're parsing and on how much traffic you get, since regex operations on large strings can get quite resource hungry. And you'd potentially be doing it on every page that attempts to display your content (unless you employ some sort of caching).

If you can parse the markdown into HTML, it follows that you could parse it back into markdown if need be. So for speed of display on your website frontend, saving it to the database in HTML means you just have to retrieve it and spit it out. For editing, you could then just parse it back into markdown as you need it.

CVM
  • 780
  • 1
  • 6
  • 10