til-to-html: A Markdown to HTML conversion tool
Published: 2023-09-16 03:42:33

## til-to-html

For this week in [Topics in Open Source Development](https://github.com/Seneca-CDOT/topics-in-open-source-2023) at Seneca College, I was tasked with writing a command line tool for [release 0.1](https://github.com/Seneca-CDOT/topics-in-open-source-2023/wiki/release-0.1).

Repository: https://github.com/paulkim26/til-to-html
Sample: https://paulkim26.github.io/til-to-html/

## What it does

[til-to-html](https://github.com/paulkim26/til-to-html) is a command line tool to convert [TIL](https://simonwillison.net/2022/Nov/6/what-to-blog-about/) posts written in [Markdown](https://www.markdownguide.org/) into static HTML pages.

## Usage Examples

Run **til-to-html -h** for additional help.

Run **til-to-html -v** for version information.

Run **til-to-html ./examples/til.txt** to generate a single webpage.

Run **til-to-html ./examples/dir** to generate multiple webpages from a folder.

Run **til-to-html ./examples/dir -o output** to output your results into a custom directory.

## Selecting my tools

The first step of this project was to determine which tools/languages/framework to work with. I wanted to work with something familiar so I could hit the ground running. I considered C++ and Python which were the first "command line" languages I could think of. However, I was curious if JavaScript could work well in this context; it turned out that it does.

I didn't want to just use Node.js though, I wanted to try something a little different. I saw this as a good opportunity to try out [Bun](https://bun.sh/) - an all-in-one JavaScript toolkit whose development I had been following for a long time. What attracted me to Bun was its holistic approach to JavaScript development - it handled all the use cases I am usually scrambling to piece together for a typical Node application (testing, file management, parsing command line arguments, etc.). I also didn't want to use Bun in a production environment since it's so new and potentially unstable - this project looked like a good opportunity to try it out with little risk.

## First impressions of Bun

I was quite impressed with Bun from the onset. Installation was painless, the documentation was robust, it covered all of my use cases, and everything worked the way it was supposed to. No longer did I need to piece together functionality from various npm packages and deal with versioning differences - Bun covered everything. It worked well as a drop in replacement for Node so the learning curve was essentially non-existent. I would highly recommend all JavaScript developers to at least look into Bun and try it out, if not for production environments.

## Developing the application

til-to-html was straightforward to develop. It parses command line arguments, checks whether the user inputted a file or folder name, reads text files, and generates a static HTML page with some minimal styling.

Markdown tags are straightforward and have very clear analogues to HTML tags. i.e. Markdown bold tags (`**`) are the equivalent of `<b>` html tags.

I had enough time to add some extra bells and whistles, such as adding a command to generate an executable version of my tool that runs without Bun as well as support for more Markdown tags such as links and italics.

Hope you have fun trying it out!