Charted Data.

Command Palette

Search for a command to run...

3 min readCharted Data

Advanced MDX Syntax and Code Highlighting

Explore the advanced syntax highlighting capabilities of this blog template. Includes line numbers, line highlighting, token highlighting, and diff support.

Charted Data uses Expressive Code to provide an IDE-grade reading experience. This guide showcases every available feature for code blocks, from basic titles to complex word-level diffs.


1. Syntax Highlighting#

The system supports dozens of programming languages out of the box with balanced, high-contrast themes.

function hello() {
console.log("Hello, world!");
}

2. Window Titles & Filenames#

Adding a title (like a filename) provides essential context and wraps the code in a professional frame.

src/lib/database.ts
import { createClient } from "@neon/serverless";
export const db = createClient(process.env.DATABASE_URL);

How to author:

```language title="src/lib/database.ts"```

3. Highlighting Specific Lines#

Focus your readers' attention by highlighting single lines, ranges, or non-consecutive lines.

example.ts
import { useRouter } from "next/navigation";
export function useRedirect() {
const router = useRouter();
return () => {
router.push("/dashboard");
};
}

How to author:

```language \{1, 3-4, 7\}```

4. Focused Lines (Dimming)#

Dim all non-selected lines to make specific logic truly pop.

logic-focus.ts
// This line is dimmed
const apiKey = process.env.API_KEY;
const client = new Client({ apiKey });
// This line is also dimmed

How to author:

```language focus=\{2-3\}```

5. Word Highlighting#

Highlight specifically chosen words or phrases throughout the entire code block.

async function getData(url) {
const res = await fetch(url);
return res.json();
}

How to author:

```javascript "fetch" "async" "await"```

6. Inline Extensions (Ins/Del)#

Show modifications or alternatives within a single line using ins and del.

import { setup } from "@/lib/engine-v4"; // Upgraded from v3

How to author:

```javascript ins="v4" del="v3"```

7. Traditional Diff Support#

Use standard diff syntax for comparing versions or showing pull-request-style changes.

Refactoring Component
function OldButton({ text }) {
return <button>{text}</button>;
}
function NewButton({ children, variant = "primary" }) {
return <button className={variant}>{children}</button>;
}

How to author:

put "-" to show it's removed
put "+" to show it's added

8. Terminal & Shell Simulation#

Shell commands are automatically detected and styled with prompts.

Terminal window
# Clone the repository
git clone https://github.com/charted-data/boilerplate.git
# Install with Bun
bun install

Multi-line Commands#

The highlighter preserves backslashes for clean terminal documentation.

Deployment
vercel deploy \
--prod \
--token $VERCEL_TOKEN \
--yes

9. Line Numbers#

Line numbers are enabled by default for all code blocks to aid technical discussion. They can be disabled if needed.

console.log("Clean output without line numbers");

How to author:

```language showLineNumbers=false```

10. Combining Features#

You can combine multiple features (Title, Highlighting, and Word Highlighting) for maximum clarity.

api/posts/[id]/route.ts
export async function PUT(req: Request) {
const data = await req.json();
// Highlighting specific operation
await db.update(posts).set(data).where(eq(posts.id, id));
return Response.json({ success: true });
}

How to author:

```language \{5\} "update" title="api/posts/[id]/route.ts"```

Happy Coding!

Download This Boilerplate ⚡