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

contentful-rich-text-figma-renderer

v0.0.1

Published

Convert Contentful Rich Text documents to formatted Figma nodes

Readme

contentful-rich-text-figma-renderer

Convert Contentful Rich Text documents into formatted Figma nodes — headings, bold/italic, lists, tables, images, and hyperlinks.

Install

npm install contentful-rich-text-figma-renderer

Usage

Pure renderer (no Figma dependency)

Convert a Contentful Rich Text Document into a flat render plan:

import {
  documentToRenderPlan,
  richTextToPlainString,
} from "contentful-rich-text-figma-renderer";

// Convert to a structured render plan (text blocks, images, tables, HRs)
const plan = documentToRenderPlan(richTextDocument);

// Or convert to a plain text string
const text = richTextToPlainString(richTextDocument);

Figma rendering

Apply the render plan to Figma nodes inside a Figma plugin:

import { documentToRenderPlan } from "contentful-rich-text-figma-renderer";
import {
  applyTextBlocksToNode,
  applyMixedContentPlan,
} from "contentful-rich-text-figma-renderer/figma";

const plan = documentToRenderPlan(richTextDocument);

// Simple: apply formatted text to an existing TextNode
await applyTextBlocksToNode(figma, textNode, plan.blocks);

// Mixed content: replaces a TextNode with a frame containing
// text, images, and tables
await applyMixedContentPlan(figma, textNode, plan.blocks, parentFrame);

The Figma functions accept the figma Plugin API as the first argument instead of relying on a global — this makes them testable and compatible with any plugin setup.

API

Main entry (contentful-rich-text-figma-renderer)

| Export | Description | | ---------------------------- | ------------------------------------------------------------------------------- | | documentToRenderPlan(doc) | Converts a Rich Text Document AST into a RichTextRenderPlan with typed blocks | | richTextToPlainString(doc) | Converts a Rich Text Document to a plain text string |

Figma entry (contentful-rich-text-figma-renderer/figma)

| Export | Description | | ------------------------------------------------------- | --------------------------------------------------------------------------------- | | applyTextBlocksToNode(figmaApi, node, blocks) | Applies rich text formatting (bold, italic, headings, lists, links) to a TextNode | | applyMixedContentPlan(figmaApi, node, blocks, parent) | Replaces a TextNode with a rich-text frame containing text, images, and tables | | resolveFontVariants(figmaApi, baseFont) | Loads bold/italic/bold-italic font variants | | getFontForSegment(segment, variants) | Returns the correct font variant for a text segment | | HEADING_SCALE | Scale factors for heading levels 1-6 |

Types

import type {
  RichTextDocument,
  RichTextBlock,
  RichTextInline,
  RichTextText,
  RichTextSegment,
  RichTextTableRow,
  RichTextRenderBlock,
  RichTextRenderPlan,
} from "contentful-rich-text-figma-renderer";

Contributing

Contributions are welcome! Here's how to get started:

  1. Fork the repo and clone it locally
  2. Install dependencies: npm install
  3. Create a branch for your change: git checkout -b my-feature
  4. Make your changes and add tests for new functionality
  5. Run the full CI check: npm run ci
  6. Commit your changes and push to your fork
  7. Open a pull request

Development commands

| Command | Description | | -------------------- | -------------------------------------- | | npm run build | Compile TypeScript to dist/ | | npm run dev | Watch mode — recompiles on file change | | npm run test | Run tests once | | npm run test:watch | Run tests in watch mode | | npm run format | Format code with Prettier | | npm run ci | Full check: build + format + tests |

Changesets

This project uses Changesets for versioning. If your PR introduces user-facing changes, add a changeset:

npx changeset

Follow the prompts to describe your change and select a semver bump level.

Guidelines

  • Keep the pure renderer (renderer.ts) free of Figma dependencies
  • Figma-specific code goes in figma.ts and is exported via the ./figma subpath
  • All Figma API functions accept figmaApi: PluginAPI as the first parameter — no globals
  • Add tests for new renderer logic (Figma functions can't be unit tested without mocks)

Sponsorship

If this package is useful to you, consider sponsoring the project. Your support helps keep it maintained and improved.

License

MIT