I wish to use Markdown for my website's leaving comments system however i have happened upon the next problem: What must i store within the database - the initial comment in Markdown, the parsed comment in HTML, or both?

I want the HTML version for viewing and also the Markdown version when the user must edit his comment. Basically keep Markdown version, I must parse your comments ought to at runtime. Basically keep HTML version, I have to convert the comment to Markdown once the user must edit it (I discovered Markdownify with this however it is not perfect). Basically store both versions, I am doubling the used space.

What will be the smartest choice? Also, so how exactly does Stack Overflow handle this?

Store both. It is going from the rules for database normalization, however i think it's worthwhile for that speed optimisation within this situation - parsing considerable amounts of text is an extremely slow operation.

You only have to store it two times, but you will need for everyone it 1000's of occasions, therefore it is an area-time trade-off.

Keep original markdown and parse at runtime. You will find a couple of issues with storing the converted version within the database.

  1. If user really wants to edit their comment, you need to backwards convert parsed into original markdown
  2. Space in database (always pass the rule when you don't have to store it, don't)
  3. Changes designed to markdown parser would need to be operate on every comment within the database, rather than just turning up at runtime.

Just render the Markdown to HTML at runtime.

In case your site incurs performance issues, the Markdown is going to be among the last things you'll consider fine-tuning. As well as then, I doubt every time they visit sense.

Just have a look in the realtime JavaScript renderer that SO uses. It's fast.

Edit: Sorry, I should have been more obvious. I meant just render in PHP. You will save yourself lots of headache -- and also you most likely convey more essential things to bother with.