Simple Markdown Parser with JavaScript and Regular Expressions

Simple Markdown Parser with JavaScript and Regular Expressions

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 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

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

JavaScript Regular Expressions Tutorial: Regular Expression Anchors

In this JavaScript Regular Expressions (Regex) tutorial, you'll learn about regular expression anchors that allow you to match a position before or after characters.

Modern Regular Expression for Web Developers: 4 Techniques You Didn’t Know

A regular expression (also known as regex) is a sequence of characters that simplify complex text processing tasks. In this article, we’ll look at four new regex features in ECMAScript that help web developers write less error-prone and more efficient code.

Quick HTTP Cookie guide in Web Development with Express

We will focus on the technical side of using cookies in your JavaScript applications. We will look at creating, using, and manipulating cookies in an Express server. Typically, it is used to track users' activities, personalization, and session management.

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Regex JavaScript | Regular Expressions in JavaScript

We will explore some practical examples of using regex in Javascript. We'll take user input for validation and provide hints for the user along the way. We'll also look at a common fix with regex that most user input will benefit from. Finally, we'll look at encoding text with encodeURI() and why we should use regex to clean the text first.