Here’s how you can get a natural glow this party season
Storing articles and parsing Markdown to HTML
In the editors of the form we just created we'll write Mardown but, in the index and show views we're going to display the html fids (remember we're displaying the sumary_html and body_html fields from the database). So how can we parse the markdown to HTML 🤔? and when do we parse it? For both questions I found different options.
How to parse it?
- Create our own parser
- Use an existing library (like Parsedown)
- Use GitHub's API via GitDown
When to parse it?
- Parse the markdown to HTML every time we display the index or show pages
- Parse the markdown to HTML before storing it in the database
At the end I opted to use GitHub's API and parse it before storing the articles in the database. There is package called GitDown that will simplify it a lot, so we'd have to install it via compose with
composer require calebporzio/gitdown . Once installed, we can go ahead and create the store method of the ArticleController, the action of the form we just created: