Git Product home page Git Product logo

nextjs-prism-markdown's Introduction

Using Prism with Next.js

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

Deploy with Vercel

nextjs-prism-markdown's People

Contributors

leerob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nextjs-prism-markdown's Issues

Adding line numbers?

Hi,

Wondering if you can help me understand how to configure remark-prism to show line numbers. I added this line:

import remark from 'remark';
import html from 'remark-html';
import prism from 'remark-prism';

export default async function markdownToHtml(markdown) {
  const result = await remark()
    .use(html)
    .use(prism, {
      plugins: ['line-numbers']
    })
    .process(markdown);
  return result.toString();
}

But the proper classnames are not being added to the generated <pre> tags.

Any ideas? Tried following https://github.com/sergioramos/remark-prism#plugins but didn't work.

Is there a way to get a list of all docs (.md files)?

This is a great boilerplate, but I am struggling to figure out how to extract all of the markdown files into a list that contains the link and document names, think something along the lines of a sidebar.

Any suggestions?

nextjs-prism-markdown not working on Next13 with app dir

I couldn't make prismjs work on the new app dir on my project.

To be sure, it was not something with my project I took your project and migrate it to the Next 13

npm i next@latest react@latest react-dom @latest

then I changed next.config.js

module.exports = {
  experimental: {
    appDir: true,
  },
  async redirects() {
    return [
      {
        source: '/',
        destination: '/prism',
        permanent: true
      }
    ];
  }
};

then I moved pages/[slug].tsx into app/[slug]/page.tsx and updated the file:

import Layout from '../../components/Layout';
import { getAllDocs, getDocBySlug } from '../../lib/docs';
import markdownToHtml from '../../lib/markdown';

export default async function Doc({ params }) {
  const doc = getDocBySlug(params.slug);
  const content = await markdownToHtml(doc.content || '');
  return <Layout meta={doc.meta}>{content}</Layout>;
}

export async function generateStaticParams() {
  const docs = getAllDocs();

  return docs.map((doc) => {
    return {
      slug: doc.slug
    }
  });
}

Still not working, even after cleaning node_modules and installing all over again.

If I try to run it as a RSC I have this error:

Screenshot 2023-04-17 at 14 31 47

If I add "use client" to try to run it as a client component (to match the behaviour of the pages dir), then I have this error:

Screenshot 2023-04-17 at 14 33 31

Super weird. And to be honest parsing markdown and html to add code highlighting is really a task that I would really avoid to execute on the client.

Do you guys at Vercel have any idea how to make this work? ๐Ÿ™

My best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.