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

bend-react-code-blocks

v0.1.0

Published

Modified Atlaskit's Code Block to support more languages (i.e graphql, reasonml, etc) and theme (i.e railscast, darcula, monokai, etc) code snippets!

Downloads

6

Readme

React components for rendering code snippets with syntax highlighting

BREAKING CHANGES: VERSION >= 0.0.8-alpha now requires a nodejs version >= 12

Background

Initially, this started as a small project looking to modify Atlaskit's Code Block component to support more languages (i.e graphql, reasonml, etc). It then rapidly evolved into a never-ending rabbithole which ended up with support for themes (i.e railscast, darcula, monokai, etc), customizable styles, and copy functionality too!

I don't plan on keeping this updated unless people are looking to actually use it. So don't be shy! Feel free to post an issue or a pr.

Demo

Netlify Status

Check out react-code-blocks

Install

Install react-code-blocks via yarn or npm

yarn add react-code-blocks
npm i react-code-blocks

Usage

Updated usage instructions can be found here

import { CopyBlock } from "react-code-blocks";
function MyCodeComponent(props) {
  return (
    <CopyBlock
      text={props.code}
      language={props.language}
      showLineNumbers={props.showLineNumbers}
      wrapLines
    />
  );
}

Components

CodeBlock

A simple code block component

import { CodeBlock, dracula } from "react-code-blocks";

function MyCoolCodeBlock({ code, language, showLineNumbers }) {
  return (
    <CodeBlock
      text={code}
      language={language}
      showLineNumbers={showLineNumbers}
      theme={dracula}
    />
  );
}

Props

Note that CodeBlock & CopyBlock share exactly the same props

| name | type | default | description | | ----------------- | --------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | | text | string | required | The code to be formatted | | language | string | "text" | The language in which the code is written. See here for a list of supported languages | | showLineNumbers | boolean | true | Indicates whether or not to show line numbers | | theme | object | dracula | A theme object for the code block. See here for a list of supported themes | | | highlight | string | "" | Lines to highlight! For multiple lines, use a comma i.e highlight="1,6,7". For a range of lines, use a - i.e highlight="1-5" for highlighting lines 1-5. |


more to come...

CopyBlock

A code block component with a little copy button for copying a snippet.

import { CopyBlock, dracula } from "react-code-blocks";

function MyCoolCodeBlock({ code, language, showLineNumbers }) {
  <CopyBlock
    text={code}
    language={language}
    showLineNumbers={showLineNumbers}
    theme={dracula}
    codeBlock
  />;
}

Props

Same as the CodeBlock's component with the exception of one!

| name | type | default | description | | ----------- | ---------- | ------- | --------------------------------------------------------------------------------------------------------------------------------- | | codeBlock | boolean | false | Indicates whether to render the CopyBlock as an inline Code component or a CodeBlock component | | onCopy | function | - | The onCopy function is called if the copy icon is clicked. This enables you to add a custom message that the code block is copied |

Supported Themes

For a list of supported themes, check out the list here

Supported Languages

For a list of supported languages, check out the list here

Alternatives

If you're looking for some more maintained solutions, I'd suggest the following:

  • react-syntax-highlighter: syntax highlighting component for react with prismjs or highlightjs ast using inline styles by @conorhastings.
    • It's actually used in this project as well! :smile:
  • react-highlight.js: A lightweight React wrapper around the Highlight.js syntax highlighting library by @bvaughn.
  • react-live: A flexible playground for live editing React components by @FormidableLabs.
  • @atlaskit/code: Renders inline code snippets and code blocks
    • Original inspiration for this project kit for this project
  • carbon-components-react: Check out their <CodeSnippet> component which supports multi-line, single-line, and inline snippets along with added copying functionality.

Feel free to add any other alternative packages here! :smile:

Todos

  • [x] Add a better readme
  • [x] Highlighting line feature
  • [x] Supported Themes documentation
  • [x] Supported Languages documentation
  • [x] Add a License
  • [ ] Docs for usage with GatsbyJS
  • [ ] Docs for usage with MDX
  • [ ] Contributor guide for development
  • [ ] Contributor guide for adding themes
  • [ ] Contributor guide for adding languages
  • [ ] Document props for Code component
  • [ ] Better demo
  • [x] Storybook with Docs
  • [x] Move to typescript
  • [ ] A component with a terminal around it. because why not!? 🧐

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

Author