Skip to content

Commit e22d7c9

Browse files
Merge pull request #39 from contentstack/next
Next : Bug Fix ~ Fix for Extra New Line issue
2 parents ca29f0a + 05f43d1 commit e22d7c9

File tree

12 files changed

+7079
-34
lines changed

12 files changed

+7079
-34
lines changed

Changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
A brief description of what changes project contains
44

5-
## Aug 8, 2023
5+
## Oct 5, 2023
6+
7+
#### v1.2.5
8+
9+
- The issue of adding an extra <br/> tag in breaks has been fixed
10+
11+
## Sep 26, 2023
612

713
#### v1.2.4
814

pom.xml

Lines changed: 1 addition & 1 deletion
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.4</version>
7+
<version>1.2.5</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>

src/main/java/com/contentstack/utils/node/NodeToHTML.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ private NodeToHTML() {
2929
*/
3030
public static String textNodeToHTML(JSONObject nodeText, Option renderOption) {
3131
String text = nodeText.optString("text");
32-
33-
// compare with the nodeText options
32+
text = text.replace("\n", "");
3433
if (nodeText.has("superscript")) {
3534
text = renderOption.renderMark(MarkType.SUPERSCRIPT, text);
3635
}

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public String renderOptions(JSONObject embeddedObject, Metadata metadata) {
5454
*/
5555
@Override
5656
public String renderMark(MarkType markType, String text) {
57-
// Replace "\n" with "<br/>" tags
58-
text = renderHtmlWithLineBreaks(text);
5957
switch (markType) {
6058
case SUPERSCRIPT:
6159
return "<sup>" + text + "</sup>";
@@ -72,7 +70,7 @@ public String renderMark(MarkType markType, String text) {
7270
case BOLD:
7371
return "<strong>" + text + "</strong>";
7472
case BREAK:
75-
return "<br />" + text;
73+
return "<br />" + text; // v1.2.5
7674
default:
7775
return text;
7876
}
@@ -101,11 +99,8 @@ private String escapeInjectHtml(JSONObject nodeObj, String nodeType) {
10199
*/
102100
@Override
103101
public String renderNode(String nodeType, JSONObject nodeObject, NodeCallback callback) {
104-
105102
String strAttrs = strAttrs(nodeObject);
106-
107103
String children = callback.renderChildren(nodeObject.optJSONArray("children"));
108-
109104
switch (nodeType) {
110105
case "p":
111106
return "<p" + strAttrs + ">" + children + "</p>";
@@ -165,28 +160,6 @@ public String renderNode(String nodeType, JSONObject nodeObject, NodeCallback ca
165160
}
166161

167162

168-
/**
169-
* Returns the string replacing </n> is with the <br/> tags
170-
*
171-
* @param content the content
172-
* @return string with br tags
173-
* @apiNote the support for the br tags are included
174-
* @since v1.3.0
175-
*/
176-
private String renderHtmlWithLineBreaks(String content) {
177-
// Replace "\n" with "<br/>" tags
178-
String htmlContent = content.replaceAll("\\n", "<br />");
179-
180-
// Now, you can render the HTML content
181-
// (You can use your rendering method here, e.g., send it to a WebView or display it in a GUI component)
182-
183-
// For demonstration purposes, let's just print it
184-
System.out.println(htmlContent);
185-
186-
return htmlContent;
187-
}
188-
189-
190163
/**
191164
* The function takes a JSONObject as input and returns a string containing the attributes and
192165
* their values, excluding certain keys.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.junit.Test;
99
import org.junit.runners.MethodSorters;
1010

11+
import java.io.IOException;
12+
1113
import static com.contentstack.utils.RTEResult.*;
1214
import static com.contentstack.utils.RTEString.*;
1315

@@ -94,4 +96,12 @@ public void testAvailableEntryItemTypes() {
9496
String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null);
9597
Assert.assertEquals(kParagraphHtml, result);
9698
}
99+
100+
@Test
101+
public void testHERFID() throws IOException {
102+
final String rte = "src/test/resources/reports/jsonviewer.json";
103+
JSONObject theRTE = new ReadResource().readJson(rte);
104+
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
105+
System.out.println(result);
106+
}
97107
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ public void testRenderFunction() {
158158

159159
@Test
160160
public void testCustomJSONRTE() {
161-
162-
163161
JSONObject rteObject = new JSONObject();
164162
String[] keyPath = {
165163
"rich_text_editor", "global_rich_multiple.group.rich_text_editor"

0 commit comments

Comments
 (0)