Skip to content

Commit b6e13c4

Browse files
committed
chore: update dependencies and enhance documentation features
- Added `github-slugger` and `rehype-slug` packages for improved heading management in markdown. - Updated layout settings in `layout.tsx` to default to dark theme and disabled system theme switching. - Refined Table of Contents components to ensure unique IDs using `github-slugger`. - Adjusted documentation content for clarity and consistency in `ROADMAP.md` and other files.
1 parent 47d81b8 commit b6e13c4

9 files changed

Lines changed: 44 additions & 22 deletions

File tree

ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document outlines the planned features and development stages for the @crea
44

55
## Overview
66

7-
The @create-markdown project provides a complete block-based markdown solution with:
7+
`@create-markdown` provides a complete block-based markdown solution with:
88

99
- **@create-markdown/core** - Zero-dependency parsing and serialization
1010
- **@create-markdown/preview** - Framework-agnostic HTML rendering with plugins

bun.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/docs/app/docs/[[...slug]]/page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { notFound } from 'next/navigation';
22
import { MDXRemote } from 'next-mdx-remote/rsc';
33
import remarkGfm from 'remark-gfm';
4+
import rehypeSlug from 'rehype-slug';
45
import { getDocBySlug, getAllDocSlugs, extractHeadings } from '@/lib/mdx';
56
import { mdxComponents } from '@/components/docs/mdx-components';
67
import { TableOfContents, MobileTOC } from '@/components/docs/toc';
@@ -69,7 +70,12 @@ export default async function DocPage({ params }: DocPageProps) {
6970
<MDXRemote
7071
source={doc.content}
7172
components={mdxComponents}
72-
options={{ mdxOptions: { remarkPlugins: [remarkGfm] } }}
73+
options={{
74+
mdxOptions: {
75+
remarkPlugins: [remarkGfm],
76+
rehypePlugins: [rehypeSlug],
77+
},
78+
}}
7379
/>
7480
</div>
7581
</article>

packages/docs/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export default function RootLayout({
4747
<body className={`${inter.variable} ${jetbrainsMono.variable} font-sans antialiased bg-background min-h-screen`}>
4848
<ThemeProvider
4949
attribute="class"
50-
defaultTheme="system"
51-
enableSystem
50+
defaultTheme="dark"
51+
enableSystem={false}
5252
disableTransitionOnChange
5353
>
5454
{/* Fixed background effects - Purple only */}

packages/docs/components/docs/toc.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

33
import * as React from 'react';
4+
import GitHubSlugger from 'github-slugger';
45
import { List, X } from 'lucide-react';
56
import { cn } from '@/lib/utils';
67

@@ -56,9 +57,9 @@ export function TableOfContents({ items = [] }: TableOfContentsProps) {
5657
<div className="space-y-2">
5758
<p className="font-medium">On This Page</p>
5859
<ul className="m-0 list-none text-sm">
59-
{items.map((item) => (
60+
{items.map((item, index) => (
6061
<li
61-
key={item.id}
62+
key={`${item.id}-${index}`}
6263
className={cn(
6364
'mt-0 pt-2',
6465
item.level === 3 && 'pl-4'
@@ -125,19 +126,19 @@ export function MobileTOC({ items = [] }: TableOfContentsProps) {
125126
);
126127
}
127128

128-
// Utility to extract headings from content
129+
// Utility to extract headings from content (use @/lib/mdx extractHeadings for doc pages).
130+
// Uses github-slugger so ids are unique and match rehype-slug output.
129131
export function extractHeadings(content: string): TocItem[] {
130132
const headingRegex = /^(#{2,3})\s+(.+)$/gm;
131133
const headings: TocItem[] = [];
134+
const slugger = new GitHubSlugger();
132135
let match;
133136

134137
while ((match = headingRegex.exec(content)) !== null) {
135138
const level = match[1].length;
136-
const text = match[2];
137-
const id = text
138-
.toLowerCase()
139-
.replace(/[^a-z0-9]+/g, '-')
140-
.replace(/(^-|-$)/g, '');
139+
const rawText = match[2];
140+
const text = rawText.replace(/\*\*/g, '').replace(/`/g, '').trim();
141+
const id = slugger.slug(text);
141142

142143
headings.push({ id, text, level });
143144
}

packages/docs/content/roadmap.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This document outlines the planned features and development stages for the @crea
99

1010
## Overview
1111

12-
The @create-markdown project provides a complete block-based markdown solution with:
12+
`@create-markdown` provides a complete block-based markdown solution with:
1313

1414
- **@create-markdown/core** - Zero-dependency parsing and serialization
1515
- **@create-markdown/preview** - Framework-agnostic HTML rendering with plugins

packages/docs/lib/mdx.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3+
import GitHubSlugger from 'github-slugger';
34
import matter from 'gray-matter';
45

56
const contentDirectory = path.join(process.cwd(), 'content');
@@ -106,20 +107,20 @@ export function getAllDocs(): Doc[] {
106107
}
107108

108109
/**
109-
* Extract headings from MDX content
110+
* Extract headings from MDX content.
111+
* Uses github-slugger so ids match rehype-slug (used when compiling MDX).
110112
*/
111113
export function extractHeadings(content: string): Array<{ id: string; text: string; level: number }> {
112114
const headingRegex = /^(#{2,3})\s+(.+)$/gm;
113115
const headings: Array<{ id: string; text: string; level: number }> = [];
116+
const slugger = new GitHubSlugger();
114117
let match;
115118

116119
while ((match = headingRegex.exec(content)) !== null) {
117120
const level = match[1].length;
118-
const text = match[2].replace(/\*\*/g, '').replace(/`/g, '');
119-
const id = text
120-
.toLowerCase()
121-
.replace(/[^a-z0-9]+/g, '-')
122-
.replace(/(^-|-$)/g, '');
121+
const rawText = match[2];
122+
const text = rawText.replace(/\*\*/g, '').replace(/`/g, '').trim();
123+
const id = slugger.slug(text);
123124

124125
headings.push({ id, text, level });
125126
}

packages/docs/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"shiki": "^3.21.0",
3030
"tailwind-merge": "^3.4.0",
3131
"gray-matter": "^4.0.3",
32-
"remark-gfm": "^4.0.0"
32+
"remark-gfm": "^4.0.0",
33+
"github-slugger": "^2.0.0",
34+
"rehype-slug": "^6.0.0"
3335
},
3436
"devDependencies": {
3537
"@tailwindcss/typography": "^0.5.15",

packages/docs/scripts/convert.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'fs';
88
import { dirname, join } from 'path';
9+
import { fileURLToPath } from 'url';
910
import { markdownToMDXWithMeta } from '@create-markdown/mdx';
1011

11-
const ROOT_DIR = join(import.meta.dir, '../../..');
12-
const OUTPUT_DIR = join(import.meta.dir, '../content');
12+
const __dirname = dirname(fileURLToPath(import.meta.url));
13+
const ROOT_DIR = join(__dirname, '../../..');
14+
const OUTPUT_DIR = join(__dirname, '../content');
1315

1416
interface FileMapping {
1517
source: string;

0 commit comments

Comments
 (0)