Before touching Shiki and rehype-pretty-code, you need to master Node.js, ESM basics, Markdown/MDX, and the AST concept. In this episode you also set up a content project, install shiki and rehype-pretty-code, then verify the pipeline for the first time.

Welcome to the Learn Shiki Rehype Pretty Code series! This series will take you to mastery of Shiki and rehype-pretty-code — the combination that makes code blocks in blogs or MD/MDX documentation appear with editor-accurate syntax highlighting, complete with line highlighting, diff, title, caption, and much more. In total there are 23 episodes arranged across six phases.
But before touching these two libraries, there are some basic skills and software you must have. Why are these pre-requisites important? Because Shiki is not just a simple regex highlighter. It uses TextMate grammar and Oniguruma WASM to tokenize code — and rehype-pretty-code works inside the unified pipeline that builds an AST tree. If these concepts aren't clear yet, every following step will feel like a black box.
Episode 0 is your roadmap: we'll make sure the basic skills are in place, set up a content project, install shiki and rehype-pretty-code, then verify that the first pipeline runs. Once this episode is done, you can follow the entire series comfortably.
Shiki and rehype-pretty-code are JavaScript packages that run on Node.js, so you must be comfortable with Node.js version 18 and above and at least one package manager: npm, bun, or pnpm. You also need to understand the basics of ESM (import and export), because both libraries are ESM-only.
node --version
npm --versionThe output of node --version must show version 18 or newer. This series uses npm because it is the most universal, but every command can be mapped to bun or pnpm without any issues.
rehype-pretty-code works on Markdown and MDX files. You need to understand basic Markdown syntax such as headings, lists, links, and especially fenced code blocks. MDX adds the ability to write JSX components inside Markdown — this concept matters because several content frameworks (for example Next.js with @next/mdx) process MDX through the rehype pipeline.
Beyond that, you must understand the AST (Abstract Syntax Tree) concept. In the HTML world, this tree is called HAST. When remark parses Markdown, the result is an MDAST tree. remark-rehype converts it into HAST, then rehype plugins (including rehype-pretty-code) manipulate that tree before it becomes an HTML string.
The core of this entire series is the unified pipeline. The flow is always the same: parse → transform → stringify.
markdown → remark-parse → MDAST → remark-rehype → HAST → rehype plugins → rehype-stringify → HTMLShiki works as the highlighting engine inside one of those rehype plugins, and rehype-pretty-code provides the layer that turns <pre> and <code> nodes into feature-rich <figure> elements. Understand this big picture before diving into code.
You can follow this series with any project: Next.js MDX, Astro, VitePress, or a plain unified project like the one we build in episode 3. For episode 0, just create an empty project directory:
mkdir code-block-project
cd code-block-project
npm init -yThe npm init -y command creates a package.json with default configuration. You need to add "type": "module" so the project uses ESM — a required step because both libraries we use are ESM-only.
With package.json ready, install the two main libraries:
npm install shiki rehype-pretty-codeThis process also pulls in supporting dependencies such as @shikijs/engine-oniguruma which loads Oniguruma WASM, and the hast-util-* packages that rehype-pretty-code uses to manipulate HAST. Wait for it to finish, then verify the versions:
npm list shiki rehype-pretty-codeMake sure shiki is at version 4.x and rehype-pretty-code at version 0.14.x. The latest versions at the time of writing this series are Shiki v4.3.1 and rehype-pretty-code v0.14.4 — update if needed by running npm view shiki version to check the current version in the registry.
Info
Both libraries are ESM-only. If your project still uses CommonJS, rename the config file to next.config.mjs (for Next.js) or add "type": "module" to package.json. We'll break down this detail in episode 3.
Most episodes in this series inspect the HTML output produced by the pipeline. Because rehype-pretty-code generates elements like <figure>, <pre>, <code>, and <span> with data attributes, you must be able to read browser devtools (the Elements tab in Chrome or Firefox). Open a page containing a code block, right-click on the code, choose Inspect, then look at attributes like data-line, data-highlighted-line, and data-rehype-pretty-code-figure. This habit will save you when debugging in episode 19.
Before moving on to episode 1, run a quick verification by creating a check.mjs file in the project root:
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypePrettyCode from "rehype-pretty-code";
import rehypeStringify from "rehype-stringify";
const result = await unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypePrettyCode, { theme: "github-dark-default" })
.use(rehypeStringify)
.process("```ts\nconst x: number = 1;\n```");
console.log(String(result));Run it with node check.mjs. If there are no errors and the output contains a <figure> tag with the data-rehype-pretty-code-figure attribute, your environment is ready. Important note: remark-parse, remark-rehype, and rehype-stringify must be installed first with npm install remark-parse remark-rehype rehype-stringify.
Here is a recap of the pre-requisites you've prepared in episode 0:
If anything is missing, stop and complete it before continuing. A strong foundation will make the remaining 22 episodes feel much lighter.
Key takeaways:
import and export.<figure> output.In episode 1 next, we'll cover history, background, and why the Shiki and rehype-pretty-code combination is needed — from the evolution of regex-based syntax highlighting, the birth of Shiki in 2018 by Pine Wu, to the birth of rehype-pretty-code in 2022 by Atomiks to fill the code block feature gap in the rehype pipeline. Make sure your environment is ready, because the Learn Shiki Rehype Pretty Code journey has just begun!