Code Hike
Code Hike is an MIT-licensed library by Rodrigo Pombo for code walkthroughs, tutorials and docs. Its MDX plugins turn Markdown into objects that a React component renders however it likes.
A new project can start from npx create-next-app -e https://github.com/code-hike/v1-starter. On a site that already renders MDX, it’s npm install codehike and two plugins:
import { remarkCodeHike, recmaCodeHike } from "codehike/mdx"
const chConfig = {}
const mdxOptions = {
remarkPlugins: [[remarkCodeHike, chConfig]],
recmaPlugins: [[recmaCodeHike, chConfig]],
jsx: true,
}
A ! in front of a heading, image or code block makes it a named block. With !!, blocks of the same name collect into an array:
## !!steps Load the user
```js !code
const user = await db.users.find(id)
```
## !!steps Check access
```js !code
if (!user.admin) throw new Forbidden()
```
parseRoot turns that into { steps: [...] }, each step with its title and code, checked against a zod schema. The walkthrough component maps over the steps, and the docs have scrollycoding, spotlight and slideshow layouts to copy and adapt.
Inside code, a comment like // !mark(1:3) annotates a range of lines. Each name maps to a handler in the project that decides how it renders, and the docs have handlers for callouts, diffs, focus and tooltips to copy.
Highlighting runs at build time or in a React Server Component. React and MDX are required.