back
▲ 1 points

Ask HN: Learning how to convert Markdown to HTML

by auraham·4y ago·4 comments·view on hn ↗
A few days ago I read this article [1] where someone explained why he built his own static site generator (SSG).

The post is an interesting reading. However, I was impressed by the comments: there is a large amount of people that write their own SSG tool set rather than using (and modifying) an existing framework.

I understand the feeling, creating an SSG is a good project for learning a new programming language. Given that, I would like to ask you for resources about converting Markdown to HTML, maybe something like [2] or a relatively-small sized project like [3].

[1] https://news.ycombinator.com/item?id=28837760

[2] https://interpreterbook.com/

[3] https://pypi.org/project/Markdown/

4 comments
Pandoc? That is how I generate html. You can use an arbitrary css stylesheet with it to get the look you want, and if you want to customize something it has a built on capacity for writing lua code to adjust how it parses the markdown
Sure! Pandoc is great option. Actually, my pelican blog is based on Pandoc.

However, I think is a bit overkill (for learning purposes) since the code base is in Haskell [1]. I would prefer something more Python-like.

[1] https://github.com/jgm/pandoc/blob/master/src/Text/Pandoc/Re...

You may already be aware, Pandoc is written in Haskell but it uses a Lua script to do the actual conversion between formats, so it's more lightweight than actually having to rework the Pandoc source, depending on what you're trying to do. It's pretty intuitive to start tweaking the Lua code to get the output you want, I have done this for a couple projects and otherwise don't really know Lua.
markdown is not a language that can be expressed with a grammar file. I would take a look at the specification, they have created an implementation and explained it in details. https://spec.commonmark.org/0.30/#appendix-a-parsing-strateg...