code-hike / bright

React Server Component for syntax highlighting
https://bright.codehike.org
1.45k stars 20 forks source link

How to just highlight code #29

Closed AugustinMauroy closed 1 year ago

AugustinMauroy commented 1 year ago

I just want to highlight code. And rest is custom component how to do that ?

amozoss commented 1 year ago

You can do this

import { Code } from 'bright';

const highlight = {
  name: 'highlight',
  MultilineAnnotation: ({ children }) => {
    return <span className="block bg-blue-700 bg-opacity-50">{children}</span>;
  },
};

const code = `
// highlight(2,3)   
console.log("hello world")
console.log("hello world")
console.log("hello world")
console.log("hello world")
`;

export function Fence() {
  return (
    <Code
      lang="js"
      extensions={[highlight]}
    >
     {code}
    </Code>
  )
}

Screenshot 2023-08-22 at 2 20 07 PM

AugustinMauroy commented 1 year ago

Ok thanks !