@novahelm/content
v2026.6.1
Published
NovaHelm content — content-management models and rendering.
Maintainers
Readme
@novahelm/content
Content processing layer for NovaHelm — TipTap extension config, server-side HTML rendering, JSON conversion, sanitization, statistics, diffing, and validation.
Quick Start
pnpm add @novahelm/contentimport { renderToHtml, htmlToJson } from "@novahelm/content";
// Convert TipTap JSON document to HTML
const html = renderToHtml(doc);
// Convert HTML back to TipTap JSON
const json = htmlToJson(htmlString);Sanitization
Strip unsafe content while preserving formatting:
import { sanitizeContent, stripContent } from "@novahelm/content";
// Sanitize — remove scripts, dangerous attrs, keep formatting
const safe = sanitizeContent(untrustedJson);
// Strip — remove ALL formatting, return plain text
const plain = stripContent(richJson);Statistics and Table of Contents
import { getContentStats, extractTableOfContents, generateExcerpt } from "@novahelm/content";
const stats = getContentStats(doc);
// { wordCount, charCount, readingTime, imageCount, linkCount }
const toc = extractTableOfContents(doc);
// [{ id, text, level }]
const excerpt = generateExcerpt(doc, { maxLength: 160 });Content Diffing
Compare two document versions:
import { diffContent } from "@novahelm/content";
const diff = diffContent(oldDoc, newDoc);
// { added, removed, changed, unchanged }Validation
Validate a TipTap JSON document against allowed node and mark types:
import { validateContent, ALLOWED_NODE_TYPES } from "@novahelm/content";
const result = validateContent(doc);
if (!result.valid) {
console.error(result.errors);
}API Reference
| Export | Description |
|--------|-------------|
| forgeExtensions | Base TipTap extension set for server-side rendering |
| renderToHtml(doc) | Convert TipTap JSON to HTML string |
| htmlToJson(html) | Convert HTML string to TipTap JSON |
| sanitizeContent(doc) | Remove unsafe nodes/marks, keep formatting |
| stripContent(doc) | Strip all formatting to plain text |
| getContentStats(doc) | Word count, reading time, image/link counts |
| extractTableOfContents(doc) | Extract heading hierarchy |
| generateExcerpt(doc, opts) | Generate a plain-text excerpt |
| diffContent(a, b) | Diff two documents |
| validateContent(doc) | Validate against allowed types |
| ALLOWED_NODE_TYPES | Set of valid node type strings |
| ALLOWED_MARK_TYPES | Set of valid mark type strings |
