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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sanuabeysekara/richtext-editor

v2.0.5

Published

A fully-featured rich text editor with LaTeX equations and image management for React

Readme

@sanuabeysekara/richtext-editor

A fully-featured React rich text editor with LaTeX equations and image management. Built from scratch without using any editor libraries.

npm version license

Features

✨ Text Formatting

  • Bold, Italic, Underline, ~~Strikethrough~~
  • Headings (H1, H2, H3)
  • Bullet and numbered lists
  • Text alignment (left, center, right)
  • Hyperlinks
  • Undo/Redo

📐 LaTeX Equations

  • Insert inline mathematical equations
  • Live preview while typing
  • Powered by KaTeX
  • Delete with hover button

🖼️ Image Management

  • Upload images to your backend
  • Inline or block alignment options
  • Drag corner handles to resize
  • Delete with hover button
  • Automatic backend cleanup
  • Max 1MB per image

👁️ Viewer Component

  • Read-only display component
  • Matches editor styling
  • Responsive design
  • No editing capabilities

🛠️ Developer Features

  • HTML code preview
  • Copy to clipboard
  • Ref methods for programmatic control
  • TypeScript ready (types coming soon)

Installation

npm install @sanuabeysekara/richtext-editor

Note: KaTeX CSS is automatically bundled - no extra imports needed!

Quick Start

import React, { useRef } from 'react'
import { RichTextEditor } from '@sanuabeysekara/richtext-editor'
import '@sanuabeysekara/richtext-editor/dist/style.css'

function App() {
  const editorRef = useRef(null)

  const saveContent = () => {
    const html = editorRef.current.getCleanedContent()
    console.log('Content:', html)
  }

  return (
    <>
      <RichTextEditor 
        ref={editorRef}
        apiUrl="http://localhost:8000"
      />
      <button onClick={saveContent}>Save</button>
    </>
  )
}

Components

RichTextEditor

The main editing component.

import { RichTextEditor } from '@sanuabeysekara/richtext-editor'

<RichTextEditor 
  ref={editorRef}
  apiUrl="http://localhost:8000"
  uploadEndpoint="/images/upload"
  deleteEndpoint="/images"
  initialContent="<p>Start here...</p>"
  onChange={(html) => console.log(html)}
  onImageUpload={(data) => console.log(data)}
  onImageDelete={(id) => console.log(id)}
/>

RichTextViewer

Read-only display component.

import { RichTextViewer } from '@sanuabeysekara/richtext-editor'

<RichTextViewer content={cleanedHtml} />

Props

RichTextEditor Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | apiUrl | string | 'http://localhost:8000' | Backend base URL | | uploadEndpoint | string | '/images/upload' | Image upload endpoint | | deleteEndpoint | string | '/images' | Image delete endpoint | | initialContent | string | '<p><br></p>' | Initial HTML content | | onChange | function | null | Content change callback | | onImageUpload | function | null | Image upload callback | | onImageDelete | function | null | Image delete callback |

RichTextViewer Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | content | string | '' | HTML content to display | | className | string | '' | Additional CSS class | | style | object | {} | Inline styles |

Ref Methods

const editorRef = useRef(null)

// Get raw HTML (with editor controls)
const raw = editorRef.current.getContent()

// Get cleaned HTML (production-ready)
const clean = editorRef.current.getCleanedContent()

// Set content
editorRef.current.setContent('<p>New content</p>')

// Clear editor
editorRef.current.clear()

// Get plain text
const text = editorRef.current.getText()

// Focus editor
editorRef.current.focus()

Backend Requirements

The editor requires a backend API with these endpoints:

Upload Image

POST /images/upload
Content-Type: multipart/form-data

Response:
{
  "success": true,
  "image_id": "uuid",
  "filename": "uuid.jpg",
  "url": "/uploads/uuid.jpg",
  "size": 123456
}

Delete Image

DELETE /images/{image_id}

Response:
{
  "success": true,
  "message": "Image deleted"
}

Backend Example: A Python FastAPI example is included in the repository.

Complete Example

import React, { useRef, useState } from 'react'
import { RichTextEditor, RichTextViewer } from '@sanuabeysekara/richtext-editor'
import '@sanuabeysekara/richtext-editor/dist/style.css'

function MyEditor() {
  const editorRef = useRef(null)
  const [savedContent, setSavedContent] = useState('')
  const [showPreview, setShowPreview] = useState(false)

  const handleSave = () => {
    const cleaned = editorRef.current.getCleanedContent()
    setSavedContent(cleaned)
    setShowPreview(true)
    
    // Save to your backend
    fetch('/api/save', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ content: cleaned })
    })
  }

  return (
    <div>
      <h1>My Editor</h1>
      
      <RichTextEditor 
        ref={editorRef}
        apiUrl="https://api.mysite.com"
        onChange={(html) => console.log('Changed:', html)}
      />
      
      <button onClick={handleSave}>Save</button>
      
      {showPreview && (
        <div>
          <h2>Preview</h2>
          <RichTextViewer content={savedContent} />
        </div>
      )}
    </div>
  )
}

Styling

Both components come with complete CSS included. No additional styling needed.

To customize, wrap in your own container or use the className and style props.

Browser Support

  • Chrome/Edge 90+
  • Firefox 88+
  • Safari 14+

License

MIT

Contributing

Issues and pull requests are welcome!

Support

For issues, questions, or feature requests, please open an issue on GitHub.