Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to store and display markdown-entered text?

Tags:

markdown

I've noticed that the wmd editor can either output HTML or markdown. Does it make more sense to store the user input (in a database) as markdown or HTML? If as markdown, what is the best way to display it on a webpage later on (any examples would be greatly appreciated).

Given that the recommendation is store it as markdown, are there any standard converters / stylesheets / anything else to actually display it afterwards?

like image 675
Jedidja Avatar asked Nov 01 '08 03:11

Jedidja


People also ask

How do you display Markdown?

Open the Markdown file in a Markdown application. Use the Markdown application to convert the Markdown file to an HTML document. View the HTML file in a web browser or use the Markdown application to convert it to another file format, like PDF.

How do I display Markdown on my website?

The first step to convert Markdown to HTML is to open your Markdown document in Atom. Then toggle the Markdown preview by pressing the CTRL+SHIFT+M keyboard shortcut. Another way to toggle the Markdown preview is from Packages —> Markdown Preview —> Toggle Preview.

How do you write text in Markdown?

Here are the basics: Italics: Add one asterisk or underscore around your text *like this* or _this_ Bold: Add two asterisks or underscores around your text **like this** or __this__ Bold and Italic: Add three asterisks or underscores around your text ***like this*** or ___this___

How do you save in Markdown?

You can write Markdown online in its editor or just paste in your completed text, then preview the formatted version on the right. Copy the formatted text for a quick export—or click the Export as menu to save your document in HTML, PDF, or plain text formats.


2 Answers

I would say it's easier to store the markdown in the database, and process it into HTML when you display it.

You could store the input as HTML, then when the user wants to edit it, use something like markdownify to convert it back to markdown - but you don't really gain anything, and lose a lot (the original markdown formatting, for one). It's also rather round-a-bout (you convert the markdown to HTML, store it. Then convert the HTML to markdown, allow the user to edit it, convert it back to HTML, and store that..)

If you are worried about performance of parsing markdown on every page-view: cache the output HTML somewhere temporary (in memory, or on disc). The HTML is easier to recreate than the source markdown

like image 182
dbr Avatar answered Nov 07 '22 20:11

dbr


Speaking from almost total ignorance of markdown and wmd:

If you want the user to be able to edit the entry later, don't you have to store it as markdown?

On retrieval/display you'd need to run it through a markdown renderer of some kind.

like image 37
Ken Gentle Avatar answered Nov 07 '22 21:11

Ken Gentle