@contentful/rich-text-react-renderer
Advanced tools
Comparing version 15.18.0 to 15.19.0
@@ -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 |
{ | ||
"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 ` `, 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 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
141388
1902
253