Skip to content

Commit 766d46f

Browse files
Reference JSON RTE, Asset as embedded object
Reference JSON RTE, Asset as embedded object
1 parent 322d7ea commit 766d46f

File tree

6 files changed

+244
-6
lines changed

6 files changed

+244
-6
lines changed

.talismanrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ threshold: medium
22

33
fileignoreconfig:
44

5-
- filename: .dccache
6-
checksum: 140eb49c2bad3edadf62c926625f3bb304e904c38f2a9a5a57e9f6dc7163f61e
5+
- filename: src/test/resources/issue/newline.json
6+
checksum: eb075c30d3769a4ac08871d8f4affca55abb21e816726a083141e0e2b94417e6
7+

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.contentstack.sdk</groupId>
77
<artifactId>utils</artifactId>
8-
<version>1.2.0-SNAPSHOT</version>
8+
<version>1.2.2</version>
99
<packaging>jar</packaging>
1010
<name>Contentstack-utils</name>
1111
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS with an API-first

src/main/java/com/contentstack/utils/AutomateCommon.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ private static String _extractKeys(@NotNull JSONObject jsonNode, Option renderOb
164164
if (filteredContent.isPresent()) {
165165
JSONObject contentToPass = filteredContent.get();
166166
return getStringOption(renderObject, metadata, contentToPass);
167+
} else {
168+
if (attrType.equalsIgnoreCase(ASSET)) {
169+
return renderObject.renderNode("img", jsonNode, nodeJsonArray -> doRawProcessing(nodeJsonArray, renderObject, embedItem));
170+
}
167171
}
168172

169173
} else {

src/main/java/com/contentstack/utils/render/DefaultOption.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,32 @@ public String renderNode(String nodeType, JSONObject nodeObject, NodeCallback ca
6363
case "p":
6464
return "<p>" + children + "</p>";
6565
case "a":
66-
return "<a href=\"" + getNodeStr(nodeObject, "href") + "\">" + children + "</a>";
66+
if (nodeObject.has("url")) {
67+
return "<a href=\"" + getNodeStr(nodeObject, "url") + "\">" + children + "</a>";
68+
}
69+
if (nodeObject.has("href")) {
70+
return "<a href=\"" + getNodeStr(nodeObject, "href") + "\">" + children + "</a>";
71+
}
72+
return children;
6773
case "img":
68-
return "<img src=\"" + getNodeStr(nodeObject, "src") + "\" />" + children;
74+
if (nodeObject.has("src")) {
75+
return "<img src=\"" + getNodeStr(nodeObject, "src") + "\" />" + children;
76+
}
77+
if (nodeObject.has("url")) {
78+
return "<img src=\"" + getNodeStr(nodeObject, "url") + "\" />" + children;
79+
}
80+
if (nodeObject.has("asset-link")) {
81+
return "<img src=\"" + getNodeStr(nodeObject, "asset-link") + "\" />" + children;
82+
}
83+
return children;
6984
case "embed":
70-
return "<iframe src=\"" + getNodeStr(nodeObject, "src") + "\"" + children + "</iframe>";
85+
if (nodeObject.has("src")) {
86+
return "<iframe src=\"" + getNodeStr(nodeObject, "src") + "\"" + children + "</iframe>";
87+
}
88+
if (nodeObject.has("url")) {
89+
return "<iframe src=\"" + getNodeStr(nodeObject, "url") + "\"" + children + "</iframe>";
90+
}
91+
return children;
7192
case "h1":
7293
return "<h1>" + children + "</h1>";
7394
case "h2":
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
uid: "node_uid_12",
3+
_version: 1,
4+
attrs: {},
5+
children: [
6+
{
7+
"uid": "node_uid_1",
8+
"type": "reference",
9+
"attrs": {
10+
"display-type": "display",
11+
"asset-uid": "asset_uid_1",
12+
"content-type-uid": "sys_assets",
13+
"asset-link": "https://image.url/11.jpg",
14+
"asset-name": "11.jpg",
15+
"asset-type": "image/jpeg",
16+
"type": "asset",
17+
"class-name": "embedded-asset",
18+
"width": 25.16914749661705,
19+
"className": "dsd",
20+
"id": "sdf"
21+
},
22+
"children": [
23+
{
24+
"text": ""
25+
}
26+
]
27+
}
28+
],
29+
type: "doc"
30+
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
{
2+
"uid": "4e52e62e39844184b139c812a94b275f",
3+
"children": [
4+
{
5+
"uid": "5c3cc441f6394f019a33632feff4c5b5",
6+
"children": [
7+
{
8+
"text": "First Heading"
9+
}
10+
],
11+
"type": "p",
12+
"attrs": {}
13+
},
14+
{
15+
"uid": "3c5625fac71c42a7b22b82f7d2370b77",
16+
"children": [
17+
{
18+
"text": "This is the article text"
19+
}
20+
],
21+
"type": "p",
22+
"attrs": {}
23+
},
24+
{
25+
"uid": "8e9ad7b9df3c48329e8d4b06aa49ccf0",
26+
"children": [
27+
{
28+
"break": true,
29+
"text": "n"
30+
},
31+
{
32+
"text": "Heading one"
33+
}
34+
],
35+
"type": "p",
36+
"attrs": {}
37+
},
38+
{
39+
"uid": "033c2b49fe834457aa2bd0dc96d2b350",
40+
"children": [
41+
{
42+
"uid": "4d919c74603245c68493bd017ae9c608",
43+
"children": [
44+
{
45+
"text": "New line of text"
46+
}
47+
],
48+
"type": "li",
49+
"attrs": {}
50+
},
51+
{
52+
"uid": "4d04733ae9994ec28f675a487970f62e",
53+
"children": [
54+
{
55+
"uid": "a4baf76597ff48c2a76e4c66e62bc900",
56+
"children": [
57+
{
58+
"text": "subheading a"
59+
}
60+
],
61+
"type": "li",
62+
"attrs": {}
63+
},
64+
{
65+
"uid": "8cead2c9a4b8456298e46983d960ef9a",
66+
"children": [
67+
{
68+
"text": "subheading b"
69+
}
70+
],
71+
"type": "li",
72+
"attrs": {}
73+
}
74+
],
75+
"type": "ol",
76+
"attrs": {}
77+
},
78+
{
79+
"uid": "0a8c5cfd07c24f67b9a96425da5bb4cb",
80+
"children": [
81+
{
82+
"text": "Another new line of text"
83+
},
84+
{
85+
"break": true,
86+
"text": "nn"
87+
},
88+
{
89+
"text": "Bold line for other lines of text",
90+
"bold": true
91+
}
92+
],
93+
"type": "li",
94+
"attrs": {}
95+
},
96+
{
97+
"uid": "0f7c312e0ef6480ba9407d94b3ab8106",
98+
"children": [
99+
{
100+
"text": "The third line of text"
101+
}
102+
],
103+
"type": "li",
104+
"attrs": {}
105+
},
106+
{
107+
"uid": "7c31fbbedc1b454ab245f8613de65591",
108+
"children": [
109+
{
110+
"text": "Fourth text line"
111+
}
112+
],
113+
"type": "li",
114+
"attrs": {}
115+
},
116+
{
117+
"uid": "27b3973cd1004edf8d65f25e9d693ba8",
118+
"children": [
119+
{
120+
"uid": "75466bd357054aa1a6487ce45d65cecc",
121+
"children": [
122+
{
123+
"text": "subheading a for 4"
124+
}
125+
],
126+
"type": "li",
127+
"attrs": {}
128+
},
129+
{
130+
"uid": "0a9e7c91000d42419e9e31371c358cc3",
131+
"children": [
132+
{
133+
"text": "subheading b for 4"
134+
}
135+
],
136+
"type": "li",
137+
"attrs": {}
138+
}
139+
],
140+
"type": "ol",
141+
"attrs": {}
142+
},
143+
{
144+
"uid": "9717d376b39a4c899e620e32c6b61322",
145+
"children": [
146+
{
147+
"text": "The fifth and last line"
148+
}
149+
],
150+
"type": "li",
151+
"attrs": {}
152+
}
153+
],
154+
"id": "f85064d50c1b40a7a2f04d6f8b927736",
155+
"type": "ol",
156+
"attrs": {}
157+
},
158+
{
159+
"uid": "53f4b8157193426d8830d77c2205f46d",
160+
"children": [
161+
{
162+
"text": ""
163+
}
164+
],
165+
"type": "p",
166+
"attrs": {}
167+
},
168+
{
169+
"uid": "3bb399aff2da4e649c8330965a70b034",
170+
"children": [
171+
{
172+
"text": ""
173+
}
174+
],
175+
"type": "p",
176+
"attrs": {}
177+
}
178+
],
179+
"type": "doc",
180+
"_version": 2,
181+
"attrs": {}
182+
}

0 commit comments

Comments
 (0)