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

meact

v0.3.1

Published

Customizable Markdown React renderer

Downloads

6

Readme

meact

Customizable Markdown React renderer

Travis npm

Installation

npm install meact

The library has two peer dependencies:

{
  "react": "15.x",
  "markdown-it": "^8.1.0"
}

Usage

import Markdown from 'meact';

text = `
# Zombo.com

Welcome to [Zombo.com](http://zombo.com). This is Zombo.com. Welcome. This is Zombo.com. Welcome to Zombo.com. You can do anything at Zombo.com. Anything at all. The only limit is yourself. Welcome to Zombo.com. Welcome to Zombo.com. This is Zombo.com. Welcome to Zombo.com. This is Zombo.com, welcome!

Yes, this is Zombo.com. This is Zombo.com, and welcome to you who have come to Zombo.com. Anything is possible at Zombo.com. You can do anything at Zombo.com. The infinite is possible is Zombo.com. The unattainable is unknown at Zombo.com. Welcome to Zombo.com. This is Zombo.com. Welcome to Zombo.com. Welcome. This is Zombo.com. Welcome to Zombo.com! Welcome to Zombo.com.
`;

<Markdown input={text} />

If you're not using a module loader, in the browser you can access the Markdown component on window.meact.default.

Customization

You can pass in a custom instance of markdown-it to the <Markdown /> component.

import markdownIt from 'markdown-it';
import emoji from 'markdown-it-emoji';

const renderer = markdownIt().use(emoji);

<Markdown renderer={renderer} />

You can also use custom components for any Markdown feature. Pass an object of React component functions/classes to the components prop of <Markdown />. Each key in the component list should be a Markdown feature—this could be a built-in feature, like paragraph or list_item, or it might be a feature from a plugin.

const components = {
  paragraph: ({ token, renderTokens }) => <p>renderTokens(token.nodes.slice(1, -1))</p>,
};

<Markdown input="The infinite is possible." components={components} />

Custom renderers get two props: token, which is the token being rendered, and renderTokens, a function to render the child nodes of the current token.

Note the use of slice() when rendering the child tokens. Many Markdown features are represented as a set of three tokens: the open token (the first one), the close token (the last one), and then everything in the middle. In the case of a paragraph, as shown above, the first token in token.nodes is paragraph_open, and the last one is paragraph_close. The middle token has the actual text content, and can be recursively rendered. So, we slice out the first and last tokens in the list when rendering children.

Not all Markdown features require this, but many do. When in doubt, inspect the contents of token and adjust your component to match what's there.

Feature Support

All of markdown-it's built-in features will render as React-based HTML. Plugins should work, but haven't been tested yet.

Features known not to work include:

  • Reference links

Features that are wonky:

  • List items have <p> elements inside them, even if the item is one line of text.

Local Development

git clone https://github.com/gakimball/meact
cd meact
npm install
npm test

License

MIT © Geoff Kimball