logo
2024-01-09 - Next.js / Markdown

Welcome

This is some random welcome text which we will replace with some cool content.
This is actually read from a Markdown file (.md).

The translator

There are many Markdown to HTML translators out there.
Since we're building a Node.js app, we need a translator that works in this environnement.

We'll be using, the best one in my humble opinion for this task, Marked, a markdown parser and compiler.

Installation

To install Marked in a Node.js application, type the following command in the terminal of your code editor:

npm install marked

You now have a powerful Markdown converter at your service 😉

Usage

To start using Marked, all we have to do is to fill its parse() method with some Markdown.
It's as simple as the following block of code:

import { marked } from 'marked';
const html = marked.parse(
  '# An H1 heading converted from Markdown to HTML with Marked!',
);

The output of the code above would be:

<h1>An H1 heading converted from Markdown to HTML with Marked!</h1>

That's all for now, see you around! 🫣