1.0.75 • Published 11 months ago

react-markdown-html-renderer v1.0.75

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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.

1.0.75

11 months ago

1.0.74

11 months ago

1.0.73

11 months ago

1.0.72

11 months ago

1.0.71

11 months ago

1.0.70

11 months ago

1.0.69

11 months ago

1.0.68

11 months ago

1.0.67

11 months ago

1.0.66

11 months ago

1.0.65

11 months ago

1.0.64

11 months ago

1.0.63

11 months ago

1.0.62

11 months ago

1.0.61

11 months ago

1.0.60

11 months ago

1.0.59

11 months ago

1.0.58

11 months ago

1.0.57

11 months ago

1.0.56

11 months ago

1.0.55

11 months ago

1.0.54

11 months ago

1.0.53

11 months ago

1.0.52

11 months ago

1.0.51

11 months ago

1.0.50

11 months ago

1.0.48

11 months ago

1.0.47

11 months ago

1.0.46

11 months ago

1.0.45

11 months ago

1.0.44

11 months ago

1.0.43

11 months ago

1.0.42

11 months ago

1.0.41

11 months ago

1.0.40

11 months ago

1.0.39

11 months ago

1.0.38

11 months ago

1.0.37

11 months ago

1.0.36

11 months ago

1.0.35

11 months ago

1.0.34

11 months ago

1.0.33

11 months ago

1.0.32

11 months ago

1.0.31

11 months ago

1.0.30

11 months ago

1.0.29

11 months ago

1.0.28

11 months ago

1.0.27

11 months ago

1.0.26

11 months ago

1.0.25

11 months ago

1.0.24

11 months ago

1.0.23

11 months ago

1.0.22

11 months ago

1.0.21

11 months ago

1.0.20

11 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.15

11 months ago

1.0.14

11 months ago

1.0.13

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago