v1.0.0 — MIT License — Zero External Runtime Dependencies

Universal Content
Rendering Library

Parse and render HTML, PHP, JSON, XML, Markdown, CSS, and source code as React components with zero-config auto-detection. One unified API for web and React Native.

7
Content Parsers
12+
React Components
8
Built-in Plugins
42
i18n Locales
15+
Code Languages
18+
Feature Modules

Everything You Need for
Content Rendering

A comprehensive toolkit that handles every aspect of content parsing, rendering, and manipulation across web and mobile platforms.

🎨

Auto Content Detection

Automatically detects HTML, HTML5, JSON, XML, PHP, Markdown, CSS, JavaScript, TypeScript, YAML, and plain text from content strings with zero config.

📄

HTML/HTML5 Rendering

Full DOM support with custom component overrides, XSS sanitization, SVG support, inline style parsing, event handlers, and scoped CSS injection.

🎯

CSS Engine

Full CSS parsing with selector matching (type, class, ID, attribute, pseudo-class, combinators), specificity calculation, CSS variables, calc(), @media queries, and scoped injection.

📝

Enhanced Markdown

Full GFM plus reference links, footnotes, definition lists, math blocks, emoji shortcodes (30+), subscript/superscript, highlight syntax, and autolinks.

💻

Code Syntax Highlighting

15+ language support with line numbers, line highlighting, copy button, dark/light themes, and customizable font sizes.

📋

JSON Interactive Viewer

Collapsible tree view with search/filter, data type badges, copy-to-clipboard, sort keys, JSONPath querying, and dark/light themes.

📎

SVG Renderer (Native)

21 SVG elements supported on React Native with zero external dependencies: paths, shapes, text, ViewBox transforms, and gradients.

📱

Virtualized Rendering

FlatList-based virtualization on native and CSS content-visibility containment on web for efficient rendering of large documents.

🔒

XSS Sanitization

Built-in XSS protection with configurable allowed tags, attributes, and strip rules. Protects all rendered HTML content by default.

🌐

i18n & RTL Support

42 supported locales, 13 RTL locales, locale-aware number/date formatting, localized UI strings in 13 languages, and automatic direction detection.

🎭

Animation Hooks

useFadeIn, useSlideIn, useCollapseAnimation, useThemeTransition, useScrollAnimation, useTypewriter, and more CSS-based animations.

📄

PDF Export

Export rendered content to PDF with full styling, page breaks, and print-optimized layouts via browser print API.

🔧

Plugin System

PluginManager with lifecycle hooks (beforeParse, afterParse, beforeRender, afterRender, transformNode, extractData) and 8 built-in plugins.

Accessibility (WCAG 2.0)

ARIA role mapping, attribute generation, color contrast checking, document outline validation, and screen reader text generation.

🚀

SSR / Next.js

renderToString, renderToStaticMarkup, extractMetadataForSSR, generateHeadTags, generateStructuredData (JSON-LD), and environment detection.

🛠

Error Recovery

Intelligent fallback strategies for HTML, JSON, Markdown, CSS, and XML errors with human-readable fix suggestions and recovery attempts.

🏥

Content Service

Fetch content from APIs (AEM, headless CMS, REST) with auto-detection, 9 extraction strategies, caching, retry, and polling.

📦

Tree-Shaking Exports

Sub-path exports for parsers, utils, hooks, plugins, themes, and types. Import only what you need to keep bundles minimal.

🔎

Content Extraction

Extract links, images, scripts, styles, meta tags, headings, tables, forms, lists, code blocks, SEO, OpenGraph, Twitter Cards, and more.

Packages

Three Packages, One Ecosystem

Install only what you need. Each package is independently versioned with sub-path exports for optimized tree-shaking.

@laddhaanshul/content-renderer-core
v1.0.0

Core parsing, utilities, hooks, plugins, themes, accessibility, SSR, i18n, error recovery, benchmarks & PDF export.

Sub-path Exports
/parsers /utils /hooks /plugins /themes /types
Dependencies
htmlparser2 ^9.0.0 entities ^4.5.0 css-tree ^2.3.1
@laddhaanshul/content-renderer
v1.0.0

Dedicated React Native components for HTML, PHP, JSON, XML, Markdown & code with native primitives.

Dependencies
@laddhaanshul/content-renderer-core 1.0.0 htmlparser2 ^9.0.0 entities ^4.5.0
Peer Dependencies
react >=17.0.0 react-native >=0.68.0
Getting Started

Install in Seconds

Add ContentRenderer to your project with your preferred package manager. No complex configuration required.

Terminal
# Install core package (parsers, utilities, hooks)
npm install @laddhaanshul/content-renderer-core

# Install React + React Native package
npm install @laddhaanshul/content-renderer
            
Code Examples

Simple API, Powerful Results

Zero-config auto-detection means you can start rendering content immediately with just a single component.

App.tsx
import { ContentRenderer } from '@laddhaanshul/content-renderer';

function App() {
  const content = '<h1>Hello World</h1><p>This is <strong>HTML</strong> content.</p>';
  return <ContentRenderer content={content} />;
}

12+ Ready-to-Use Components

Every component works on both web and React Native with platform-appropriate rendering. Each accepts extensive props for customization.

ContentRenderer
Universal auto-detection renderer
HTMLRenderer
Full HTML/HTML5 with CSS engine
MarkdownRenderer
GFM + extended syntax support
JSONRenderer
Interactive tree viewer
CodeRenderer
Syntax-highlighted code blocks
PHPRenderer
PHP code with PHPDoc extraction
XMLRenderer
Collapsible XML tree viewer
CSSRenderer
CSS syntax highlighting
DiffRenderer
Side-by-side diff viewer
SVGRenderer
21 SVG elements on native
ContentServiceRenderer
API content fetch & render
VirtualizedHTMLRenderer
Large document virtualization
Parsers

7 Powerful Parsers

Each parser provides comprehensive methods for parsing, validating, querying, and transforming content.

Parser Key Capabilities
HTMLParser Full DOM, query selectors, serialization, validation
JSONParser JSONPath, diff, schema inference, flatten/unflatten
XMLParser XPath queries, namespaces, toObject conversion
MarkdownParser GFM, frontmatter, TOC, link/image extraction
PHPParser Class/function/variable extraction, PHPDoc
CSSParser Specificity, media queries, keyframes, variables
CSEngine Cascade, CSS vars, calc(), @media evaluation
Plugin System

Extensible Plugin Architecture

The PluginManager provides priority-based plugin hooks for every stage of the content rendering pipeline. Register custom plugins or use 8 production-ready built-in plugins.

Plugin Hook Description
lineNumbers afterParse Adds line numbers to code blocks
sanitize beforeRender Applies HTML sanitization
toc extractData Generates table of contents
metaEnricher afterParse Enriches metadata with SEO data
linkRewrite transformNode Rewrites link URLs via mapping
imageProxy transformNode Proxies images through CDN
emoji afterParse Converts emoji shortcodes to Unicode
headingAnchor transformNode Adds anchor IDs to headings
Plugin Registration
import { PluginManager, builtInPlugins } from '@laddhaanshul/content-renderer-core';

const manager = new PluginManager();
manager.use(builtInPlugins.lineNumbers());
manager.use(builtInPlugins.sanitize({ allowedTags: ['p', 'a', 'img', 'h1', 'h2'] }));
manager.use(builtInPlugins.toc());
manager.use(builtInPlugins.headingAnchor());

// Register a custom plugin with priority ordering
manager.register({
  name: 'my-plugin',
  version: '1.0.0',
  priority: 50,
  beforeParse(content: string): string {
    return content.replace(/\r\n/g, '\n');
  },
  transformNode(node: HTMLNode): HTMLNode {
    return node; // Modify nodes before rendering
  },
});
Architecture

Clean Monorepo Architecture

Built as a Yarn Workspaces monorepo with clear separation between core logic and platform-specific rendering.

Your Application

Web App (Next.js / Vite) • React Native App (Expo / Bare)

@laddhaanshul/content-renderer

12+ Components, Animation Hooks, Themes

@laddhaanshul/content-renderer

Native Components, TurboModules, Fabric

@laddhaanshul/content-renderer-core

7 Parsers • CSEngine • Plugins • Hooks • HOCs • Provider • i18n • Accessibility • SSR • Error Recovery • PDF Export • Benchmarks • Sanitization • Extraction • Validation • Transform

htmlparser2

Fast HTML/XML Parsing

css-tree

CSS AST Parsing

entities

Entity Encode/Decode

Built-in Utility Modules

Comprehensive utility functions for content extraction, sanitization, transformation, validation, and more.

🔍

Content Extraction

Extract links, images, scripts, styles, meta, headings, tables, forms, lists, code blocks, comments, SEO, OpenGraph, Twitter Cards, and structured data (JSON-LD).

🛡

Sanitization

sanitizeHTML, stripTags, stripAttributes, stripScripts, stripStyles, escapeHTML, unescapeHTML, encodeEntities, and decodeEntities with configurable options.

🔃

Transform

minify/format HTML/CSS/JSON/XML, convert between formats (JSON, XML, Markdown, HTML), string utilities (slugify, camelCase, kebabCase, snakeCase, pascalCase, titleCase).

Validation

isValidHTML, isValidJSON, isValidXML, isValidCSS, isValidURL, isValidEmail, isValidPhoneNumber, content type detection from extension, MIME type, and file header.

📊

Benchmarks

benchmarkParse, benchmarkExtract, benchmarkRender, benchmarkSuite, compareWithCompetitors, and formatBenchmarkResults for performance measurement.

🚀

Error Recovery

recoverFromHTMLError, recoverFromJSONError, recoverFromMarkdownError, recoverFromCSSError, recoverFromXMLError, suggestFixes, and createFallbackContent.

Ready to Build?

Start rendering content in your React or React Native app today. One package, every content type, zero configuration.

⚡ Install ContentRenderer 💻 View on GitHub