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

@marp-team/marp-react

v0.0.4

Published

Marp renderer component for React

Downloads

38

Readme

@marp-team/marp-react

Storybook CircleCI Codecov npm LICENSE

Marp renderer component for React.

Before using Marp React

This component is suited to create presentation tools integrated with Marp by React. Marp would create the static slide contents consist of plain HTML and CSS, so you have to notice that it's not suited to control the content of your slide via React.

React community has more appropriate and awesome tools for such that purpose. Typically these tools should help if you want to create a beautiful slide deck via React:

  • Spectacle can create and control your slide deck with React's some flexibilities.
  • mdx-deck is the best alternative for creating slide deck based on MDX: Markdown + React components.

If you really think to need, you can even use Marp React within these frameworks.

Install

# yarn
yarn add @marp-team/marp-core @marp-team/marp-react

# npm
npm install --save @marp-team/marp-core @marp-team/marp-react

Usage

<Marp> component

This is a simple usage of <Marp> renderer component. It renders slides via inline SVG to <div> elements.

import { Marp } from '@marp-team/marp-react'
import React from 'react'
import ReactDOM from 'react-dom'

const markdown = `
# Page 1

---

## Page 2`

ReactDOM.render(<Marp markdown={markdown} />, document.getElementById('app'))

/* <div id="app">
 *   <div class="marp-xxxxxxxx">
 *     <svg data-marpit-svg viewBox="0 0 1280 960">
 *       <foreignObject width="1280" height="960">
 *         <section><h1>Page 1</h1></section>
 *       </foreignObject>
 *     </svg>
 *   </div>
 *   <div class="marp-xxxxxxxx">
 *     <svg data-marpit-svg viewBox="0 0 1280 960">
 *       <foreignObject width="1280" height="960">
 *         <section><h2>Page 2</h2></section>
 *       </foreignObject>
 *     </svg>
 *   </div>
 * </div>
 */

Constructor option

Marp constructor options can change in options prop.

<Marp
  markdown=":+1:"
  options={{
    inlineSVG: false,
    emoji: {
      shortcode: true,
      unicode: true,
    },
  }}
/>

Custom renderer

You can use a custom renderer by passing render prop or children prop.

// Use `render` prop
<Marp markdown="# Hello, Marp!" render={customRenderer} />

// or children
<Marp markdown="# Hello, Marp!">{customRenderer}</Marp>

The example of custom renderer is here:

const customRenderer = slides => (
  <div className="marp">
    {slides.map(({ slide, comments }, i) => (
      <div className="slide" key={i}>
        {slide}
        {comments.map((comment, ci) => (
          <p className="comment" key={ci}>
            {comment}
          </p>
        ))}
      </div>
    ))}
  </div>
)

:information_source: See also Render Props in the document of React.

markdown-it plugins

You can use markdown-it plugins by configuring Marp object via init prop.

<Marp
  markdown={text(
    'Markdown',
    `
::: columns
The delimiter \`:::\` should not be shown here.
:::
  `
  )}
  init={marp => marp.use(markdownItContainer, 'columns')}
/>

<MarpWorker> component (Experimental)

For the best performance of the integrated web app, <MarpWorker> allows using Web Worker for Markdown conversion. It has a lot of clear advantages over a regular <Marp> component.

  • It does not block UI thread while converting large Markdown.
  • A blazing fast live preview by a simple but clever queueing system is available.
  • No longer need to include a huge Marp Core into main JS.
  • Web Worker will be loaded asynchronously, so the first paint will not block.

The renderer using worker may be default component of Marp React in future.

Basic usage

You can use it just by swapping from <Marp> to <MarpWorker>. By default, <MarpWorker> will use a pre-built worker via jsDelivr CDN.

import { MarpWorker } from '@marp-team/marp-react'
import React from 'react'
import ReactDOM from 'react-dom'

ReactDOM.render(
  <MarpWorker markdown="# Hello, Marp Worker!" />,
  document.getElementById('app')
)

Use custom worker

The custom worker may specify via worker prop.

<MarpWorker worker={new Worker('worker.js')} markdown="# Hello, Marp Worker!" />
// worker.js
require('@marp-team/marp-react/lib/worker')()

Initial rendering

<MarpWorker>'s custom renderer might be called with undefined slides argument, unlike <Marp>. It means an initial rendering of the component while preparing worker.

You may show waiting user a loading message as follows:

<MarpWorker worker={new Worker('worker.js')} markdown="# Hello, Marp Worker!">
  {slides =>
    slides ? (
      <div className="marp">
        {slides.map(({ slide }) => (
          <div className="slide" key={i}>
            {slide}
          </div>
        ))}
      </div>
    ) : (
      <p>Loading Marp Worker...</p>
    )
  }
</MarpWorker>

Author

Managed by @marp-team.

License

MIT License