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-markdown-html-renderer

v1.0.75

Published

A flexible React component for rendering Markdown and HTML content with TypeScript support

Downloads

79

Readme

Markdown HTML Renderer

A flexible and customizable React component for rendering Markdown content with advanced image handling capabilities.

Author

Avneesh Kumar

Features

  • Renders Markdown content to HTML
  • Supports custom image and link rendering
  • Handles various image formats and syntaxes
  • Supports newlines in image alt text
  • Clickable images with custom click handler
  • Sanitizes output HTML for security
  • Customizable tag processing

Installation

To install the Markdown Renderer Plugin, you can use npm or yarn:

npm install react-markdown-html-renderer

# or
yarn add react-markdown-html-renderer

Usage

Here's a basic example of how to use the MarkdownRenderer component:

import React from "react";
import { MarkdownRenderer } from "react-markdown-html-renderer";

const MyComponent = () => {
  const markdownContent = `
    # Hello World

    This is a paragraph with an image:
    ![Example Image](https://example.com/image.jpg)

    And here's a [link](https://example.com)
  `;

  const handleImageClick = (url) => {
    console.log("Image clicked:", url);
    // Handle image click, e.g., open in a modal
  };

  return <MarkdownRenderer content={markdownContent} onImageClick={handleImageClick} />;
};

export default MyComponent;

Props

The MarkdownRenderer component accepts the following props:

  • content (string, required): The Markdown content to render.
  • customTags (array, optional): An array of custom tag objects for additional Markdown processing.
  • onImageClick (function, optional): A callback function that receives the image URL when an image is clicked.

Custom Tags

You can extend the Markdown processing by providing custom tags. Here's an example:

const customTags = [
  {
    name: "CustomImage",
    type: "image",
    replacement: (match, indicator, src, url) => {
      return `<img src="${url}" alt="${indicator}" class="custom-image" />`;
    },
  },
];

<MarkdownRenderer
  content={markdownContent}
  customTags={customTags}
  onImageClick={handleImageClick}
/>;

Security

This plugin uses DOMPurify to sanitize the rendered HTML, helping to prevent XSS attacks. However, always be cautious when rendering user-generated content.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.