Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prism-react-renderer

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prism-react-renderer

Renders highlighted Prism output using React

  • 0.1.7
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is prism-react-renderer?

The prism-react-renderer package is a React component that leverages PrismJS, a syntax highlighter written in JavaScript, to render syntax-highlighted code in React applications. It is highly customizable and can be used to implement code highlighting with various themes and styles directly in React projects.

What are prism-react-renderer's main functionalities?

Syntax Highlighting

This feature allows developers to easily implement syntax highlighting in their React applications. The code sample demonstrates how to use prism-react-renderer to highlight JavaScript code with the 'darcula' theme.

import React from 'react';
import { render } from 'react-dom';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { darcula } from 'react-syntax-highlighter/dist/esm/styles/prism';

const Component = () => {
  const codeString = '(num) => num + 1';
  return (
    <SyntaxHighlighter language='javascript' style={darcula}>
      {codeString}
    </SyntaxHighlighter>
  );
};

render(<Component />, document.getElementById('root'));

Custom Theming

This feature demonstrates how to apply a custom theme (in this case, 'nightOwl') to the code highlighting. It shows the flexibility of prism-react-renderer in terms of theming and customization.

import React from 'react';
import Highlight, { defaultProps } from 'prism-react-renderer';
import theme from 'prism-react-renderer/themes/nightOwl';

const exampleCode = `function add(a, b) {
  return a + b;
}`;

const Component = () => (
  <Highlight {...defaultProps} theme={theme} code={exampleCode} language='javascript'>
    {({ className, style, tokens, getLineProps, getTokenProps }) => (
      <pre className={className} style={style}>
        {tokens.map((line, i) => (
          <div {...getLineProps({ line, key: i })}>
            {line.map((token, key) => (
              <span {...getTokenProps({ token, key })} />
            ))}
          </div>
        ))}
      </pre>
    )}
  </Highlight>
);

export default Component;

Other packages similar to prism-react-renderer

FAQs

Package last updated on 27 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc