Skip to content

Commit cb03f3c

Browse files
Merge pull request #49 from contentstack/feat/json_rte
feat: added support for fragments
2 parents 4cac4de + d7d2fbc commit cb03f3c

File tree

5 files changed

+147
-2
lines changed

5 files changed

+147
-2
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.contentstack.sdk</groupId>
66
<artifactId>utils</artifactId>
7-
<version>1.2.6</version>
7+
<version>1.2.7</version>
88
<packaging>jar</packaging>
99
<name>Contentstack-utils</name>
1010
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS</description>
@@ -28,7 +28,7 @@
2828
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
2929
<validation-version>2.0.1.Final</validation-version>
3030
<json-version>20231013</json-version>
31-
<spring-web-version>6.0.13</spring-web-version>
31+
<spring-web-version>6.0.18</spring-web-version>
3232
<org.apache.commons-text>1.10.0</org.apache.commons-text>
3333
</properties>
3434

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ public String renderNode(String nodeType, JSONObject nodeObject, NodeCallback ca
154154
return "<code" + strAttrs + ">" + children + "</code>";
155155
case "reference":
156156
return "";
157+
case "fragment":
158+
return "<fragment" + strAttrs + ">" + children + "</fragment>";
157159
default:
158160
return children;
159161
}

src/test/java/com/contentstack/utils/RTEResult.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ public class RTEResult {
2323
public static String kWFSFeesHtml = "<p redactor-attributes=\"{}\" style=\"\" dir=\"ltr\">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <br /><br /><br />\t\t\t\tUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. <br />Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. <br />\tExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>";
2424

2525
public static String kONEHtml = "<p redactor-attributes=\"{}\" style=\"\" dir=\"ltr\"><br />A paragraph with break set as trueA paragraph with line break <br /> and \t tab</p>";
26+
27+
public static String kFragment = "<ul redactor-attributes=\"{}\" style=\"\" dir=\"ltr\"><li redactor-attributes=\"{}\" style=\"\" dir=\"ltr\"><fragment><strong>One</strong></fragment><ul style=\"\"><li redactor-attributes=\"{}\" style=\"\" dir=\"ltr\">nested one </li><li redactor-attributes=\"{}\" style=\"\" dir=\"ltr\">nested two </li></ul></li><li redactor-attributes=\"{}\" style=\"\" dir=\"ltr\">Two</li></ul>";
2628
}

src/test/java/com/contentstack/utils/TestRte.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,14 @@ public void testIssueOct() throws IOException {
152152
// Assert.assertEquals(kONEHtml, result);
153153
}
154154

155+
@Test
156+
public void testFragment() throws IOException {
157+
final String rte = "src/test/resources/reports/fragment.json";
158+
JSONObject rteFragment = new ReadResource().readJson(rte);
159+
String[] keyPath = {"json_rte"};
160+
Utils.jsonToHTML(rteFragment, keyPath, new DefaultOption());
161+
Assert.assertEquals(kFragment, rteFragment.get("json_rte"));
162+
}
163+
155164

156165
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
"title": "",
3+
"json_rte":
4+
{
5+
"type": "doc",
6+
"attrs":
7+
{},
8+
"uid": "71ff5918b9434999b97c97629aecc32e",
9+
"children":
10+
[
11+
{
12+
"uid": "6b80a5ead10445bf939d39c1f033bed9",
13+
"type": "ul",
14+
"children":
15+
[
16+
{
17+
"uid": "bf242d94ca4847b6a7144c57c03d0c84",
18+
"type": "li",
19+
"attrs":
20+
{
21+
"style":
22+
{},
23+
"redactor-attributes":
24+
{},
25+
"dir": "ltr"
26+
},
27+
"children":
28+
[
29+
{
30+
"type": "fragment",
31+
"children":
32+
[
33+
{
34+
"text": "One",
35+
"bold": true
36+
}
37+
],
38+
"uid": "cc6c5b25a77f443ba7b7cc1c1a92e7cb"
39+
},
40+
{
41+
"uid": "388cdd29331e46859cb78806c30aab52",
42+
"type": "ul",
43+
"attrs":
44+
{
45+
"style":
46+
{}
47+
},
48+
"children":
49+
[
50+
{
51+
"type": "li",
52+
"attrs":
53+
{
54+
"style":
55+
{},
56+
"redactor-attributes":
57+
{},
58+
"dir": "ltr"
59+
},
60+
"uid": "5e35c7de876e463a80d5b7e7bb3dbb46",
61+
"children":
62+
[
63+
{
64+
"text": "nested one "
65+
}
66+
]
67+
},
68+
{
69+
"type": "li",
70+
"attrs":
71+
{
72+
"style":
73+
{},
74+
"redactor-attributes":
75+
{},
76+
"dir": "ltr"
77+
},
78+
"uid": "23015f6106ad47db9142a01fa6e5465c",
79+
"children":
80+
[
81+
{
82+
"text": "nested two "
83+
}
84+
]
85+
}
86+
]
87+
}
88+
]
89+
},
90+
{
91+
"type": "li",
92+
"attrs":
93+
{
94+
"style":
95+
{},
96+
"redactor-attributes":
97+
{},
98+
"dir": "ltr"
99+
},
100+
"uid": "6c3fe490f18347b896d3ac2ec982d389",
101+
"children":
102+
[
103+
{
104+
"text": "Two"
105+
}
106+
]
107+
}
108+
],
109+
"id": "10b11adfd2be427bb20f9e24122a6b48",
110+
"attrs":
111+
{
112+
"style":
113+
{},
114+
"redactor-attributes":
115+
{},
116+
"dir": "ltr"
117+
}
118+
}
119+
],
120+
"_version": 1
121+
},
122+
"tags":
123+
[],
124+
"locale": "en-us",
125+
"uid": "blt9a8011fa3669348b",
126+
"created_by": "blta7bacfb988d2bf5c",
127+
"updated_by": "blt734e8a0a85290dd1",
128+
"created_at": "2024-02-08T10:58:07.835Z",
129+
"updated_at": "2024-02-13T10:59:49.357Z",
130+
"_version": 9,
131+
"_in_progress": true
132+
}

0 commit comments

Comments
 (0)