/nextjs-prism-markdown

Example using Prism / Markdown with Next.js including switching syntax highlighting themes.

Primary LanguageJavaScript

Using Prism with Next.js

Example using Prism / Markdown with Next.js including switching syntax highlighting themes.

Deploy with Vercel

Example code block to test remark-prism

// lib/docs.js

import fs from 'fs';
import { join } from 'path';
import matter from 'gray-matter';

export function getDocBySlug(slug) {
  const realSlug = slug.replace(/\.md$/, '');
  const docsDirectory = join(process.cwd(), 'docs');
  const fullPath = join(docsDirectory, `${realSlug}.md`);
  const fileContents = fs.readFileSync(fullPath, 'utf8');
  const { data, content } = matter(fileContents);

  return { slug: realSlug, meta: data, content };
}