Markdown is a markup language like HTML. It is quite popular among developers to write blogs, readme files, documentation and blogs. Some of the popular websites that support rich text like Reddit, GitHub, Notion etc allow you to write Markdown. I use Markdown to convert my blog from a Markdown file to HTML web pages. Markdown is simple yet very powerful. In this blog, I will be writing about how to build a simple Markdown parser to convert Markdown to HTML with JavaScript using Regular Expressions.

How does Markdown text look like

If you open a markdown file, you’ll see the following syntax.

Markdown text example

Learn more from this Markdown cheatsheet.

Regular Expressions

A regular expression is a character sequence that helps us to capture patterns in a text. We can use it to validate user input, find and replace texts and yup, you guessed it, build our Markdown parser. 😉

Different languages have different ways to represent RegEx. Here is how it is done in JavaScript.

Markdown example in JavaScript

I will explain the patterns we use in our parser as we reach that section.

Markdown parser

The Markdown parser I intend to build is a function that takes Markdown text as input and returns HTML.

#regular-expressions #web-development #programming #markdown #javascript

Simple Markdown Parser with JavaScript and Regular Expressions
30.10 GEEK