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?
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.
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.
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___
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With