Code Hike

1.1.0 · active · verified Tue Apr 21

Code Hike is an open-source library designed to enhance web content by transforming standard Markdown into rich, interactive experiences using React. Currently stable at version 1.1.0, the project demonstrates an active release cadence with frequent patch updates and a significant major release (v1.0.0) in August 2024. Its core functionality revolves around providing 'Fine-grained Markdown' and 'Headless codeblocks', which are key differentiators. Unlike traditional syntax highlighters, Code Hike parses the Abstract Syntax Tree (AST) of code blocks, enabling advanced features like line focusing, callouts, diffs, and interactive elements directly within code comments. This allows developers to build custom React components for rendering code and markdown, giving complete control over UI and behavior. It is built on the MDX ecosystem and integrates seamlessly with React-based frameworks like Next.js, making it ideal for code walkthroughs, tutorials, interactive blog posts, and comprehensive documentation sites.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core setup for Code Hike with MDX and a custom React Server Component for rendering code blocks with highlighting and annotations.

import { remarkCodeHike, recmaCodeHike } from 'codehike/mdx'
import { Pre, RawCode, highlight } from 'codehike/code'
import 'codehike/style.css'

// next.config.mjs (or similar MDX configuration)
const chConfig = {
  // Define a custom component to render code blocks
  components: { code: 'MyCode' },
  syntaxHighlighting: {
    theme: 'github-dark'
  }
}

const mdxOptions = {
  remarkPlugins: [[remarkCodeHike, chConfig]],
  recmaPlugins: [[recmaCodeHike, chConfig]],
  jsx: true,
}

// app/components/MyCode.tsx (React Server Component)
// This component renders an annotated code block.
export async function MyCode({ codeblock }: { codeblock: RawCode }) {
  const highlighted = await highlight(codeblock, "github-dark");
  return <Pre code={highlighted} />;
}

// app/page.mdx (example MDX content)
// ```js
// console.log("Hello from Code Hike!")
// // ! focus
// ```

view raw JSON →