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

markdown-to-react-components

v0.2.4

Published

Convert markdown into react components

Downloads

1,392

Readme

markdown-to-react-components

Convert markdown into react components

Whats different?

There are several projects that claims to convert markdown using React, but that is not exactly right. They produce one single React component with some plain markdown converted HTML in it. They do not produce React components of the markdown syntax. But this project does!

Features

  • Converts markdown syntax to React components. It is a lot more performant on live changes
  • Define your own components to be used as headers, lists etc.
  • Code highlighting using Prism.js
  • Also returns a TOC (Table Of Contents), based on headers used
  • TOC and Header ids match so that you can use anchor links (<a href="#my-heading>My heading</a>)

Install

npm install markdown-to-react-components

How to use

import React from 'react';
import MTRC from 'markdown-to-react-components';

MTRC.configure({
  h1: React.createClass({
    render() {
      return <h1 id={this.props.id} style={{color: 'red'}}>{this.props.children}</h1>
    }
  })
});

const Editor = React.createClass({
  getInitialState() {
    return {
      content: null
    };
  },
  onTextareaChange(event) {
    this.setState({
      content: MTRC(event.target.value).tree
    });
  },
  render() {
    return (
      <div>
        <div>{this.state.content}</div>
        <textarea onChange={this.onTextareaChange}/>
      </div>
    );
  }
});

export default Editor;

Code highlight

You will have to include the Prism.js library and its css manually in your project. Look in the example app to see how this is done.


    ```javascript
    var foo = 'bar';
    ```

    ```html
    <h1>Hello world!</h1>
    ```

Supported languages can be found over at prism.js.

API

Configure

Allows you to configure custom elements for your markdown.

MTRC.configure({
  h1: React.createClass({
    render() {
      return <h1 style={{color: 'red'}}>{this.props.children}</h1>
    }
  })
});
  • h1: this.props.children, this.props.id
  • h2: this.props.children, this.props.id
  • h3: this.props.children, this.props.id
  • h4: this.props.children, this.props.id
  • blockquote: this.props.children
  • hr: -
  • ol: this.props.children
  • ul: this.props.children
  • p: this.props.children
  • table: this.props.children
  • tr: this.props.children
  • th: this.props.children
  • td: this.props.children
  • td: this.props.children
  • a: this.props.children, this.props.href, this.props.title, this.props.target
  • strong: this.props.children
  • em: this.props.children
  • br: -
  • del: this.props.children
  • img: this.props.src, this.props.alt
  • code: this.props.language, this.props.code
  • codespan: this.props.children

Convert

MTRC('# Hello there').tree // React virtual dom tree
MTRC('# Hello there').toc // [{children: [], level: 1, title: 'Hello there', id: 'hello-there'}]

Run demo

  • npm install
  • npm start
  • Go to: http://localhost:8080/webpack-dev-server/bundle