# A static site generator when I decided to start blogging, it was mostly for me to learn and remember all tech thing I learnt throughout time. I also want to explore a wide diversity of technology, not focus on a particular one. Hence to start blogging, I obviously needed a static site generator. Many of them exist already, like Hugo for example, however rewriting one from scratch is typically the kind of exercise I want to throw myself into. The advantage of a static site is clearly its loading speed : a simple html file, combined with a small licked css, and a whole new blog is born Anyway, writing this static site generator from scratch is also the perfect excuse to explore a not so widely know technology to manipulate text files. ## Introduction to AWK AWK, from the intials of its creator, is an old an powerful text file maniulation. Syntactically close to C, it is a scripting language to manipulation text entries. Its [wikipedia page](https://en.wikipedia.org/wiki/AWK) sums up nicely its story. I thought it was clever to use is for a site generator, to parse markdown files and generate html ones. However, according to this [listing](https://jamstack.org/generators/) of static site generator programs, another one has had the same idea. Hence, the following, as well as my code is heavily inspired by [Zodiac](https://github.com/nuex/zodiac) (even though the repo has not been touched for 8years). ## Parsing markdown Following the official [syntax](https://daringfireball.net/projects/markdown/syntax), is a good start for a parser. AWK works as follow : it takes an optional regex and execute some code between bracket, as a function, at each line of the text input. For example : /^#/ { print "
" replaceEmAndStrong($0) "
" } else if (env == "blockquote") { print $0 } } AS `BEGIN`, AWK provide the possibilty to execute code at the very end of the file, with the `END` keyword. Naturally we need to empty the stack and close all html tags that might have been opened during the parsing. It only is a while loop, until the last environement is "none", as it way initiated : END { env = last() while (env != "none") { env = pop() print "" env ">" env = last() } } This way we are able to simply parse markdown and turn it into an HTML file. Of course I am aware that is lacks emphasis, strong and code within a line of text. However I did implement it, but maybe it will be explained in another edit of this post. Nonetheless the code can still be consulted on [github](https://github.com/SiwonP/bob). # A testing suite for markdown parser Having a markdown parser is cool, having one well tested id better. I embarked in writing a testing suite for markdown parsers. I wanted it to be generic, meaning you only had to provide a parsing program, that takes markdown in the standard input, and returns html in the standard output. All tests would be provided by the test suite.