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-code-view

v2.4.0

Published

Code view for React

Downloads

426

Readme

React Code View

React Code View can render source code in markdown documents. And brings you the ability to render React components with editable source code and live preview.

React Code View

Install

npm install react-code-view

Configure Webpack

// webpack.config.js
export default {
  module: {
    rules: [
      {
        test: /\.md$/,
        loader: 'react-code-view/webpack-md-loader'
      }
    ]
  }
};

Options

{
  "parseLanguages": [
    // Supported languages for highlight.js
    // default: "javascript", "bash", "xml", "css", "markdown", "less", "typescript"
    // See https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md
  ],
  "htmlOptions": {
    // HTML Loader options
    // See https://github.com/webpack-contrib/html-loader#options
  },
  "markedOptions": {
    // Pass options to marked
    // See https://marked.js.org/using_advanced#options
  }
}

webpack.config.js


export default {
  module: {
    rules: [
      {
        test: /\.md$/,
        use:[
          loader: 'react-code-view/webpack-md-loader',
          options:{
            parseLanguages: ['typescript','rust']
          }
        ]
      }
    ]
  }
};

Usage

import CodeView from 'react-code-view';
import { Button } from 'rsuite';

import 'react-code-view/styles/react-code-view.css';

return (
  <CodeView
    dependencies={{
      Button
    }}
  >
    {require('./example.md')}
  </CodeView>
);

The source code is written in markdown, refer to example.md

Note: The code to be rendered must be placed between <!--start-code--> and <!--end-code-->

Props

<CodeView>

| Name | Type | Default value | Description | | ----------------- | --------------------------------- | ----------------------- | ------------------------------------------------------------------------- | | afterCompile | (code: string) => string | | Executed after compiling the code | | beforeCompile | (code: string) => string | | Executed before compiling the code | | children | any | | The code to be rendered is executed. Usually imported via markdown-loader | | compileOptions | object | defaultTransformOptions | https://github.com/alangpierce/sucrase#transforms | | dependencies | object | | Dependent objects required by the executed code | | editable | boolean | false | Renders a code editor that can modify the source code | | editor | object | | Editor properties | | onChange | (code?: string) => void | | Callback triggered after code change | | onCloseEditor | () => void | | Callback triggered when the editor is closed | | onOpenEditor | () => void | | Callback triggered when the editor is opened | | renderExtraFooter | () => ReactNode | | Customize the rendering footer | | renderToolbar | (buttons: ReactNode) => ReactNode | | Customize the rendering toolbar | | sourceCode | string | | The code to be rendered is executed | | theme | 'light' , 'dark' | 'light' | Code editor theme, applied to CodeMirror |