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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-ai-highlight-parser

v1.0.4

Published

Parse and render AI streaming responses with semantic highlighting. Supports multiple modes (highlights, underline, both) and color palettes.

Readme

react-ai-highlight-parser

A parser for rendering AI responses with semantic highlighting. Built this because I needed a way to make AI outputs more readable in my projects.

npm license

What it does

Takes AI responses with highlight codes like [Y]important[/Y] and renders them with colors. Three modes: background highlights, underlines, or both. Two color palettes included.

  • ✅ Works with streaming responses
  • ✅ Protects code blocks
  • ✅ Cleans up broken or incomplete tags

Demo

Used in production at veraOS

Installation

npm install react-ai-highlight-parser

Quick Start

Using the React Component

import { HighlightRenderer } from 'react-ai-highlight-parser';

function ChatMessage({ content }) {
  return (
    <HighlightRenderer 
      content={content}
      mode="both"        // 'highlights' | 'underline' | 'both' | 'none'
      palette="vibrant"  // 'vibrant' | 'natural'
    />
  );
}

Using the Parser Function

import { parseHighlights } from 'react-ai-highlight-parser';

const aiResponse = "This is [Y]important[/Y] and this is [B]a concept[/B]";
const html = parseHighlights(aiResponse, 'highlights', 'vibrant');

// Returns HTML string with styled spans

Highlight Codes

The AI uses these codes to mark semantic content:

| Code | Color | Meaning | |------|-------|---------| | [Y] | Yellow | Important/Key points | | [B] | Blue | Concepts/Definitions | | [O] | Orange | Steps/Sequences | | [G] | Green | Success/Positive | | [R] | Red | Warnings/Errors | | [P] | Pink | Examples | | [L] | Light Blue | Data/Numbers | | [GR] | Gray | Code/Technical | | [H] | Purple | Emphasis | | [BR] | Brown | Context/Background |

Example AI Response

Here's how to [O]set up your project[/O]:

1. [Y]Install dependencies[/Y] — this is crucial
2. [B]Configure your environment[/B]
3. [G]Run the tests[/G]

[R]Warning: Don't skip step 1![/R]

Modes

highlights (default)

Applies background colors only.

underline

Applies colored underlines only.

both

Combines background colors with underlines.

none

Removes all highlight codes, returns plain text.

Palettes

vibrant (default)

Bright, saturated colors for high contrast.

natural

Earth tones and muted colors for a softer look.

API Reference

parseHighlights(text, mode?, palette?)

Parses text and returns HTML string with highlight styles.

parseHighlights(
  text: string,
  mode?: 'highlights' | 'underline' | 'both' | 'none',
  palette?: 'vibrant' | 'natural'
): string

<HighlightRenderer />

React component that renders highlighted content.

<HighlightRenderer
  content={string}
  mode={'highlights' | 'underline' | 'both' | 'none'}
  palette={'vibrant' | 'natural'}
  className={string}
/>

<HighlightSpan />

Same as HighlightRenderer but renders as <span> instead of <div>.

processResponse(text)

Cleans AI response: removes invalid codes, protects code blocks, fixes orphaned tags.

removeHighlightCodes(text)

Strips all highlight codes, keeping only the text content.

hasHighlights(text)

Returns true if text contains any highlight codes.

extractHighlightCodes(text)

Returns array of highlight codes used in the text.

Prompting Your AI

To get the AI to use these codes, add this to your system prompt:

When responding, use semantic highlighting codes to emphasize important content:
- [Y]text[/Y] for important points
- [B]text[/B] for concepts/definitions
- [O]text[/O] for steps/sequences
- [G]text[/G] for positive/success
- [R]text[/R] for warnings/errors
- [P]text[/P] for examples
- [L]text[/L] for data/numbers
- [GR]text[/GR] for code/technical
- [H]text[/H] for emphasis
- [BR]text[/BR] for context

Use sparingly for clarity. Don't highlight entire paragraphs.

License

MIT © Julio Calvo