npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-syntax

v0.0.1

Published

react-syntax React component

Downloads

40

Readme

RePrism

Travis npm package Coveralls

Modular Syntax highlighting for the web.

Inspiration

The original Prism.js is probably one of the best syntax highlighters ever created for javascript. It's extremely performant, and comes packed with tons of languages that people have worked hard to support. However, it wasn't created to play nice with tomorrow's module bundlers like Webpack, Rollup, or Parcel (despite it's claims to do so). RePrism is the answer to that need.

Features

  • 100% Prism Theme compatibility
  • SSR compatible
  • Feature Parity for all original Prism languages
  • Modular & Bundler friendly
  • Near-full support for plugins

Installation

# yarn
$ yarn add reprism
# npm
$ npm install --save reprism

Basic Usage

Reprism's core comes packaged with the same 4 default languages that Prism does:

  • markup
  • clike
  • css
  • javascript

All you need is a Prism theme and you can use reprism right away!

import { highlight } from "reprism";

import "prismjs/themes/prism-okaidia.css";

const htmlCode = `
  <div>
  <ul>
    <li className='foo' alt='bar' style="background: red;">
      Hello!
    </li>
  </ul>
  </div>
`;

const highlightedCode = reprism(htmlCode, "html");
// <span class=\\"token tag\\"><span class=\\"token tag\\"><span class=\\"token punctuation\\...

Using Prism Themes

Good news! You can use any prism compatible theme that you want, out of the box. Just make sure the styles are loaded, and you're good to go! You can do this any number of ways using various bundlers and plugins or even traditional <link> tags.

Here are the themes we recommend:

Languages

RePrism supports all of the same languages that Prism does, but they have been upgraded to play nicely with bundlers. Click here for the complete directory of updated languages.

To use these languages, simply import them and load them using RePrism's loadLanguages export. Here's an example of loading the jsx syntax and using it:

import { highlight, loadLanguages } from "reprism";
import jsx from "reprism/lanugages/jsx";

loadLanguages(jsx);

const jsxCode = `
  const element = (
    <div>
      <ul>
        {items.map(item => (
          <li key={item.id} className='foo'>
            {item.name}
          </li>
        ))}
      </ul>
    </div>
  )
`;

const highlightedCode = reprism(jsxCode, "jsx");
// <span class=\\"token keyword\\">const</span> element <span class=\\"token operator\\">=</span> <span class=\\"token punctuation\\">(</span>...

Plugins

As long as they are used strictly in the browser, most original Prism plugins should work just fine as long as you provide them the global Prism object:

// Import the Prism Api
import Prism from "reprism";

// When in the browser
if (typeof document !== "undefined") {
  // Provide window.Prism for plugins
  window.Prism = Prism;
  require("prismjs/plugins/copy-to-clipboard");
}

Migrating Other Languages

If you have a language that wasn't already ported from the original Prism list, then you can easily upgrade it to work with RePrism like so:

export default {
  language: "yourLanguageID",
  init: Prism => {
    // Insert your original Prism language code
  }
};

That's it!