Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contember/react-richtext-renderer

Package Overview
Dependencies
Maintainers
0
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contember/react-richtext-renderer

  • 2.0.0-alpha.19
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
801
increased by24.77%
Maintainers
0
Weekly downloads
 
Created
Source

Contember Rich Text renderer

This package provides a React renderer for Contember Rich Text format.

Installation

yarn add @contember/react-richtext-renderer

Usage for blocks

import { RichTextBlocksRenderer } from '@contember/react-richtext-renderer'

const App = () => {
	const blocks = [] // blocks from Contember API

	return (
		<RichTextBlocksRenderer
			blocks={blocks}
			sourceField={'content'}
			referencesField={'references'}
			referenceDiscriminationField={'type'}
		/>
	)
}

Usage for standalone rich text field

import { RichTextFieldRenderer } from '@contember/react-richtext-renderer'

const App = () => {
	const value = {} // value from Contember API

	return (
		<RichTextFieldRenderer
			source={value}
		/>
	)
}

Custom elements

import { RichTextBlocksRenderer } from '@contember/react-richtext-renderer'

const App = () => {
	// ...    
	return (
		<RichTextBlocksRenderer
			// ...
			renderElement={it => {
				if (it.element.type === 'blockquote') {
					return <blockquote>{it.children}</blockquote>
				}
				return it.fallback
			}}
		/>
	)
}

Custom leafs

import { RichTextBlocksRenderer } from '@contember/react-richtext-renderer'

const App = () => {
	// ...    
	return (
		<RichTextBlocksRenderer
			// ...
			renderLeaf={it => {
				if (it.leaf.isSup) {
					return <sup>{it.fallback}</sup>
				}
				return it.fallback
			}}
		/>
	)
}

Make sure to use it.fallback instead of it.children in renderLeaf callback, to render already applied leafs as well.

Custom references

import { RichTextBlocksRenderer } from '@contember/react-richtext-renderer'

const App = () => {
	// ...    
	return (
		<RichTextBlocksRenderer
			// ...
			referenceRenderers={{
				image: ({ reference }) => <img src={reference.url} />,
			}}
		/>
	)
}

FAQs

Package last updated on 04 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc