Skip to content

Commit 54e1fc7

Browse files
Merge pull request #55 from contentstack/next
Next
2 parents bff6967 + 6362eea commit 54e1fc7

9 files changed

+673
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [1.3.3](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.2) (2024-02-28)
4+
- Fix for parsing nested children when entry is referenced as link
5+
36
## [1.3.2](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.2) (2024-02-14)
47
- Added style attribute fragment as
58

__test__/gql/gql-json-to-html.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ describe('Node parser reference content', () => {
120120

121121
GQL.jsonToHTML({entry, paths})
122122

123-
expect(entry[0].single_rte).toEqual('<a href=\"undefined\">/copy-of-entry-final-02</a>')
124-
expect(entry[0].multiple_rte).toEqual(['<a href=\"undefined\">/copy-of-entry-final-02</a>'])
123+
expect(entry[0].single_rte).toEqual('<a href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>')
124+
expect(entry[0].multiple_rte).toEqual(['<a href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>'])
125125
done()
126126
})
127127

__test__/json-to-html.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
styleObj,
2929
unorderListJson1,
3030
unorderListJson2,
31-
orderListJson2,} from './mock/json-element-mock'
31+
orderListJson2,
32+
testJsonRte,} from './mock/json-element-mock'
3233
import {
3334
blockquoteHtml,
3435
codeHtml,
@@ -51,7 +52,9 @@ import {
5152
plainTextHtmlWithId,
5253
htmlTextIdInAttrs,
5354
classAndIdAttrsHtml,
54-
styleObjHtml } from './mock/json-element-mock-result'
55+
styleObjHtml,
56+
referenceObjHtml,
57+
referenceObjHtmlBlock} from './mock/json-element-mock-result'
5558
describe('Node parser paragraph content', () => {
5659
it('Should accept proper values', done => {
5760
const entry = { uid: 'uid'}
@@ -148,6 +151,17 @@ describe('Node parser reference content', () => {
148151
expect(entry[0].rte).toEqual(['<img src="/asset_uid_1/dummy.pdf" alt="Alternet Text" />'])
149152
done()
150153
})
154+
155+
it('should convert to html when and type is reference, attrs type is entry and display-type is link', done => {
156+
const entry = testJsonRte
157+
const paths = ["content","json_rte", "modular_blocks.block.json_rich_text"]
158+
jsonToHTML({ entry: entry, paths })
159+
entry.modular_blocks.forEach((blocks) => {
160+
expect(blocks.block.json_rich_text).toEqual(referenceObjHtmlBlock)
161+
});
162+
expect(entry.json_rte[0]).toEqual(referenceObjHtml)
163+
done()
164+
})
151165
})
152166

153167
describe('Node parse text Content', () => {

__test__/mock/json-element-mock-result.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ const h3Html = "<h3><strong><em><u><sub>Mauris venenatis dui id massa sollicitud
66
const h4Html = "<h4><strong><em><u><sub>MaNullam feugiat turpis quis elit interdum, vitae laoreet quam viverra</sub></u></em></strong></h4>"
77
const h5Html = "<h5>Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.</h5>"
88
const h6Html = "<h6>Nunc porta diam vitae purus semper, ut consequat lorem vehicula.</h6>"
9-
const orderListHtml = "<ol class=\"table\" id=\"table_id\"><li style=\"text-align:justify;\">Morbi in quam molestie, fermentum diam vitae, bibendum ipsum.</li><li style=\"text-align:justify;\">Pellentesque mattis lacus in quam aliquam congue</li><li style=\"text-align:justify;\">Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus.</li><li style=\"text-align:justify;\">Sed in ante lacinia, molestie metus eu, fringilla sapien.</li></ol>"
9+
const orderListHtml = "<ol class=\"table\" id=\"table_id\"><li style=\"text-align:justify;\" class=\"class\">Morbi in quam molestie, fermentum diam vitae, bibendum ipsum.</li><li style=\"text-align:justify;\">Pellentesque mattis lacus in quam aliquam congue</li><li style=\"text-align:justify;\">Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus.</li><li style=\"text-align:justify;\">Sed in ante lacinia, molestie metus eu, fringilla sapien.</li></ol>"
1010
const unorderListHtml = "<ul class=\"table\" id=\"table_id\"><li>Sed quis metus sed mi hendrerit mollis vel et odio.</li><li>Integer vitae sem dignissim, elementum libero vel, fringilla massa.</li><li>Integer imperdiet arcu sit amet tortor faucibus aliquet.</li><li>Aenean scelerisque velit vitae dui vehicula, at congue massa sagittis.</li></ul>"
1111
const imgHtml = "<img src=\"https://image.url/Donald.jog.png\" />"
12-
const tableHtml = "<table><thead><tr><th><p>Header 1</p></th><th><p>Header 2</p></th></tr></thead><tbody><tr><td><p>Body row 1 data 1</p></td><td><p>Body row 1 data 2</p></td></tr><tr><td><p>Body row 2 data 1</p></td><td><p>Body row 2 data 2</p></td></tr></tbody></table>"
12+
const tableHtml = "<table><thead class=\"class\"><tr><th><p>Header 1</p></th><th><p>Header 2</p></th></tr></thead><tbody class=\"class\" id=\"id\"><tr class=\"class\" id=\"id\"><td><p>Body row 1 data 1</p></td><td class=\"class\" id=\"id\"><p>Body row 1 data 2</p></td></tr><tr id=\"class\"><td><p>Body row 2 data 1</p></td><td><p class=\"class\">Body row 2 data 2</p></td></tr></tbody></table>"
1313
const blockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</blockquote>"
1414
const codeHtml = "<code>Code template.</code>"
1515
const linkInPHtml = "<strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\">LINK</a>"
1616
const linkInPURLHtml = "<strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\" target=\"_blank\">LINK</a>"
17-
const styleinPHtml = "<p style=\"text-align:right;\">This is <span>second</span> <u>JSON</u> entry</p><p style=\"text-align:left;\"><a href=\"example.com\" target=\"_blank\">Example</a></p>"
17+
const styleinPHtml = "<p style=\"text-align:right;\">This is <span>second</span> <u>JSON</u> entry</p><p style=\"text-align:left;\"><a class=\"class\" href=\"example.com\" target=\"_blank\">Example</a></p>"
1818
const plainTextHtmlWithClass = "<p class=\"class_p\"><span class=\"yellow\">abc</span><u><span class=\"blue\">ghi</span></u><strong><em><u><span class=\"orange\" id=\"blue\">Basic</span></u></em></strong><h1><span class=\"purple\">abc</span></h1></p>"
1919
const plainTextHtmlWithId = "<p class=\"class_p\"><em><u><span id=\"blue\">data</span></u></em></p>"
2020
const htmlTextIdInAttrs = "<p id=\"id_p\"><em><u>data</u></em></p>"
2121
const classAndIdAttrsHtml = "<a class=\"class_a\" id=\"id_p\" href=\"LINK.com\">link</a><img class=\"class_img\" id=\"id_img\" src=\"https://dummyImage.url/Donald.jog.png\" /><h1 class=\"class_h1\" id=\"id_h1\">heading1</h1><h2 class=\"class_h2\" id=\"id_h2\">heading2</h2><h3 class=\"class_h3\" id=\"id_h3\">heading3</h3><h4 class=\"class_h4\" id=\"id_h4\">heading4</h4><h5 class=\"class_h5\" id=\"id_h5\">heading5</h5><h6 class=\"class_h6\" id=\"id_h6\">heading6</h6>"
2222
const styleObjHtml = "<h1 style=\"text-align:justify;\">heading1</h1><h2 style=\"text-align:left;\">heading2</h2><h3 style=\"text-align:right;\">heading3</h3><h4 style=\"text-align:justify;\">heading4</h4><h5 style=\"text-align:justify;\">heading5</h5><h6 style=\"text-align:justify;\">heading6</h6>"
23+
const referenceObjHtml = "<p><a href=\"/test\" target=\"_self\">Embed entry as a link</a></p><p><a href=\"/entry-3\" target=\"_blank\">Open entry as a link in new tab</a></p><p><a href=\"/entry-2\" target=\"_self\">Bold entry</a></p><p><a href=\"/entry-4\" target=\"_blank\"><strong>Bold entry open in new tab</strong></a></p>"
24+
const referenceObjHtmlBlock = "<p><a href=\"/Test\" target=\"_self\">Embed entry as a link</a></p><p><a href=\"undefined\" target=\"_blank\">Embed entry as a link open in new tab</a></p><ul><li><a href=\"undefined\" target=\"_self\">Entry as a link</a></li><li><a href=\"undefined\" target=\"_blank\">Open entry as a link in new tab</a></li><li><a href=\"undefined\" target=\"_self\"><strong><u>Entry as a link bold</u></strong></a></li><li><a href=\"khjgf\" target=\"_blank\"><strong><u>Open bold entry as a link in new tab </u></strong></a></li><li><a href=\"https://\" target=\"_self\"><strong><u>Link URL</u></strong></a></li><li><a href=\"https://\" target=\"_blank\"><strong><u>Open link in new tab</u></strong></a></li></ul>"
2325
export {
2426
h1Html,
2527
h2Html,
@@ -42,5 +44,7 @@ export {
4244
plainTextHtmlWithId,
4345
htmlTextIdInAttrs,
4446
classAndIdAttrsHtml,
45-
styleObjHtml
47+
styleObjHtml,
48+
referenceObjHtml,
49+
referenceObjHtmlBlock
4650
}

0 commit comments

Comments
 (0)