Socket
Socket
Sign inDemoInstall

@contentful/rich-text-react-renderer

Package Overview
Dependencies
Maintainers
172
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentful/rich-text-react-renderer - npm Package Compare versions

Comparing version 15.18.0 to 15.19.0

42

dist/lib/__test__/index.test.js

@@ -55,2 +55,6 @@ "use strict";

(0, documents_1.headingDoc)(rich_text_types_1.BLOCKS.HEADING_2),
(0, documents_1.headingDoc)(rich_text_types_1.BLOCKS.HEADING_3),
(0, documents_1.headingDoc)(rich_text_types_1.BLOCKS.HEADING_4),
(0, documents_1.headingDoc)(rich_text_types_1.BLOCKS.HEADING_5),
(0, documents_1.headingDoc)(rich_text_types_1.BLOCKS.HEADING_6),
];

@@ -132,3 +136,3 @@ docs.forEach(function (doc) {

sys: {
urn: 'crn:contentful:::content:spaces/6fqi4ljzyr0e/entries/9mpxT4zsRi6Iwukey8KeM',
urn: 'crn:contentful:::content:spaces/6fqi4ljzyr0e/environments/master/entries/9mpxT4zsRi6Iwukey8KeM',
type: 'ResourceLink',

@@ -190,4 +194,4 @@ linkType: 'Contentful:Entry',

id: '9mpxT4zsRi6Iwukey8KeM',
link: 'Link',
type: 'Entry',
type: 'Link',
linkType: 'Entry',
},

@@ -199,2 +203,15 @@ },

});
it('renders resource hyperlink', function () {
var entry = {
target: {
sys: {
urn: 'crn:contentful:::content:spaces/6fqi4ljzyr0e/environments/master/entries/9mpxT4zsRi6Iwukey8KeM',
type: 'Link',
linkType: 'Entry',
},
},
};
var document = (0, documents_1.inlineEntityDoc)(entry, rich_text_types_1.INLINES.RESOURCE_HYPERLINK);
expect((0, __1.documentToReactComponents)(document)).toMatchSnapshot();
});
it('renders embedded entry', function () {

@@ -205,4 +222,4 @@ var entry = {

id: '9mpxT4zsRi6Iwukey8KeM',
link: 'Link',
type: 'Entry',
type: 'Link',
linkType: 'Entry',
},

@@ -214,2 +231,15 @@ },

});
it('renders embedded resource', function () {
var entry = {
target: {
sys: {
urn: 'crn:contentful:::content:spaces/6fqi4ljzyr0e/environments/master/entries/9mpxT4zsRi6Iwukey8KeM',
type: 'ResourceLink',
linkType: 'Contentful:Entry',
},
},
};
var document = (0, documents_1.inlineEntityDoc)(entry, rich_text_types_1.INLINES.EMBEDDED_RESOURCE);
expect((0, __1.documentToReactComponents)(document)).toMatchSnapshot();
});
});

@@ -349,3 +379,3 @@ describe('appendKeyToValidElement', function () {

});
describe.only('preserveWhitespace', function () {
describe('preserveWhitespace', function () {
it('preserves spaces between words', function () {

@@ -352,0 +382,0 @@ var options = {

@@ -45,3 +45,9 @@ "use strict";

_a[rich_text_types_1.INLINES.ENTRY_HYPERLINK] = function (node) { return defaultInline(rich_text_types_1.INLINES.ENTRY_HYPERLINK, node); },
_a[rich_text_types_1.INLINES.RESOURCE_HYPERLINK] = function (node) {
return defaultInlineResource(rich_text_types_1.INLINES.RESOURCE_HYPERLINK, node);
},
_a[rich_text_types_1.INLINES.EMBEDDED_ENTRY] = function (node) { return defaultInline(rich_text_types_1.INLINES.EMBEDDED_ENTRY, node); },
_a[rich_text_types_1.INLINES.EMBEDDED_RESOURCE] = function (node, children) {
return defaultInlineResource(rich_text_types_1.INLINES.EMBEDDED_RESOURCE, node);
},
_a[rich_text_types_1.INLINES.HYPERLINK] = function (node, children) { return react_1.default.createElement("a", { href: node.data.uri }, children); },

@@ -64,2 +70,9 @@ _a);

}
function defaultInlineResource(type, node) {
return (react_1.default.createElement("span", { key: node.data.target.sys.urn },
"type: ",
node.nodeType,
" urn: ",
node.data.target.sys.urn));
}
/**

@@ -66,0 +79,0 @@ * Serialize a Contentful Rich Text `document` to React tree

@@ -486,3 +486,9 @@ 'use strict';

_a[dist_4.ENTRY_HYPERLINK] = function (node) { return defaultInline(dist_4.ENTRY_HYPERLINK, node); },
_a[dist_4.RESOURCE_HYPERLINK] = function (node) {
return defaultInlineResource(dist_4.RESOURCE_HYPERLINK, node);
},
_a[dist_4.EMBEDDED_ENTRY] = function (node) { return defaultInline(dist_4.EMBEDDED_ENTRY, node); },
_a[dist_4.EMBEDDED_RESOURCE] = function (node, children) {
return defaultInlineResource(dist_4.EMBEDDED_RESOURCE, node);
},
_a[dist_4.HYPERLINK] = function (node, children) { return React__default.createElement("a", { href: node.data.uri }, children); },

@@ -505,2 +511,9 @@ _a);

}
function defaultInlineResource(type, node) {
return (React__default.createElement("span", { key: node.data.target.sys.urn },
"type: ",
node.nodeType,
" urn: ",
node.data.target.sys.urn));
}
/**

@@ -507,0 +520,0 @@ * Serialize a Contentful Rich Text `document` to React tree

4

package.json
{
"name": "@contentful/rich-text-react-renderer",
"version": "15.18.0",
"version": "15.19.0",
"main": "dist/rich-text-react-renderer.es5.js",

@@ -51,3 +51,3 @@ "typings": "dist/types/index.d.ts",

},
"gitHead": "fdf1744e4680b38e9f855a84220c7eead05f4775"
"gitHead": "3664afadae95d9a499abc96985abfaaa5d6967fe"
}

@@ -180,5 +180,7 @@ # rich-text-react-renderer

- `EMBEDDED_ENTRY` (this is different from the `BLOCKS.EMBEDDED_ENTRY`)
- `EMBEDDED_RESOURCE`
- `HYPERLINK`
- `ENTRY_HYPERLINK`
- `ASSET_HYPERLINK`
- `RESOURCE_HYPERLINK`

@@ -219,1 +221,34 @@ The `renderMark` keys should be one of the following `MARKS` properties as defined in [`@contentful/rich-text-types`](https://www.npmjs.com/package/@contentful/rich-text-types):

```
#### Preserving Whitespace
The `options` object can include a `preserveWhitespace` boolean flag. When set to `true`, this flag ensures that multiple spaces in the rich text content are preserved by replacing them with `&nbsp;`, and line breaks are maintained with `<br />` tags. This is useful for content that relies on specific formatting using spaces and line breaks.
```javascript
import { documentToReactComponents } from '@contentful/rich-text-react-renderer';
const document = {
nodeType: 'document',
content: [
{
nodeType: 'paragraph',
content: [
{
nodeType: 'text',
value: 'Hello world!',
marks: [],
},
],
},
],
};
const options = {
preserveWhitespace: true,
};
documentToReactComponents(document, options);
// -> <p>Hello&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;world!</p>
```
In this example, the multiple spaces between "Hello" and "world!" are preserved in the rendered output.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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