How to approach db markup repository for custom content?

I was thinking about allowing users to edit the contents of the site at a discount, as it is simple and simple. Now the question is, how can I save this input - should I convert it to html to save and then save the raw HTML in the database or save markdown text and re-split it into HTML for each request? Should I use a different approach (write static files, etc.)? I'm just wondering how to approach this problem, and how sites like stackoverflow do it. thanks.

+7
source share
1 answer

I would probably keep both the original Markdown and the HTML version of the content. In fact, I did similar things (with minimal HTML removed instead of Markdown), where I saved both the original and formatted versions.

If you want to edit the content after it is created, you will need the original Markdown, as it will probably be easier to work with than some ugly Markdown that came out of the Markdown-to-HTML converter. Keeping Markdown around will also make it easier to keep track of change history or change HTML format in the future.

Displaying content is likely to be more common than creating or editing. So you probably want HTML to be convenient to avoid repeating the same Markdown to HTML conversion over and over again.

If you have only Markdown, you pay extra for each display. If you only have HTML, you will get the ugly and unreadable / unchangeable Markdown. If you have both, you pay for a small amount of disk space, but get the opportunity to easily restore your HTML with a different internal structure, easy to track change history, easy to edit and get cheap displays as a happy side effect. In addition, storing both makes it easy to store snippets for bulk listings (such as /questions lists on SO), and these lists will be cheap because you dump data directly from the repository to a page with minimal processing.

+12
source

All Articles