1.0.75 • Published 1 year ago

react-markdown-html-renderer v1.0.75

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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

1 year ago

1.0.74

1 year ago

1.0.73

1 year ago

1.0.72

1 year ago

1.0.71

1 year ago

1.0.70

1 year ago

1.0.69

1 year ago

1.0.68

1 year ago

1.0.67

1 year ago

1.0.66

1 year ago

1.0.65

1 year ago

1.0.64

1 year ago

1.0.63

1 year ago

1.0.62

1 year ago

1.0.61

1 year ago

1.0.60

1 year ago

1.0.59

1 year ago

1.0.58

1 year ago

1.0.57

1 year ago

1.0.56

1 year ago

1.0.55

1 year ago

1.0.54

1 year ago

1.0.53

1 year ago

1.0.52

1 year ago

1.0.51

1 year ago

1.0.50

1 year ago

1.0.48

1 year ago

1.0.47

1 year ago

1.0.46

1 year ago

1.0.45

1 year ago

1.0.44

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.41

1 year ago

1.0.40

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.37

1 year ago

1.0.36

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago