Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

A brief description of what changes project contains

## Aug 8, 2023
## Oct 5, 2023

#### v1.2.5

- The issue of adding an extra <br/> tag in breaks has been fixed

## Sep 26, 2023

#### v1.2.4

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.contentstack.sdk</groupId>
<artifactId>utils</artifactId>
<version>1.2.4</version>
<version>1.2.5</version>
<packaging>jar</packaging>
<name>Contentstack-utils</name>
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS</description>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/contentstack/utils/node/NodeToHTML.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ private NodeToHTML() {
*/
public static String textNodeToHTML(JSONObject nodeText, Option renderOption) {
String text = nodeText.optString("text");

// compare with the nodeText options
text = text.replace("\n", "");
if (nodeText.has("superscript")) {
text = renderOption.renderMark(MarkType.SUPERSCRIPT, text);
}
Expand Down
29 changes: 1 addition & 28 deletions src/main/java/com/contentstack/utils/render/DefaultOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public String renderOptions(JSONObject embeddedObject, Metadata metadata) {
*/
@Override
public String renderMark(MarkType markType, String text) {
// Replace "\n" with "<br/>" tags
text = renderHtmlWithLineBreaks(text);
switch (markType) {
case SUPERSCRIPT:
return "<sup>" + text + "</sup>";
Expand All @@ -72,7 +70,7 @@ public String renderMark(MarkType markType, String text) {
case BOLD:
return "<strong>" + text + "</strong>";
case BREAK:
return "<br />" + text;
return "<br />" + text; // v1.2.5
default:
return text;
}
Expand Down Expand Up @@ -101,11 +99,8 @@ private String escapeInjectHtml(JSONObject nodeObj, String nodeType) {
*/
@Override
public String renderNode(String nodeType, JSONObject nodeObject, NodeCallback callback) {

String strAttrs = strAttrs(nodeObject);

String children = callback.renderChildren(nodeObject.optJSONArray("children"));

switch (nodeType) {
case "p":
return "<p" + strAttrs + ">" + children + "</p>";
Expand Down Expand Up @@ -165,28 +160,6 @@ public String renderNode(String nodeType, JSONObject nodeObject, NodeCallback ca
}


/**
* Returns the string replacing </n> is with the <br/> tags
*
* @param content the content
* @return string with br tags
* @apiNote the support for the br tags are included
* @since v1.3.0
*/
private String renderHtmlWithLineBreaks(String content) {
// Replace "\n" with "<br/>" tags
String htmlContent = content.replaceAll("\\n", "<br />");

// Now, you can render the HTML content
// (You can use your rendering method here, e.g., send it to a WebView or display it in a GUI component)

// For demonstration purposes, let's just print it
System.out.println(htmlContent);

return htmlContent;
}


/**
* The function takes a JSONObject as input and returns a string containing the attributes and
* their values, excluding certain keys.
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/contentstack/utils/TestRte.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.junit.Test;
import org.junit.runners.MethodSorters;

import java.io.IOException;

import static com.contentstack.utils.RTEResult.*;
import static com.contentstack.utils.RTEString.*;

Expand Down Expand Up @@ -94,4 +96,12 @@ public void testAvailableEntryItemTypes() {
String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null);
Assert.assertEquals(kParagraphHtml, result);
}

@Test
public void testHERFID() throws IOException {
final String rte = "src/test/resources/reports/jsonviewer.json";
JSONObject theRTE = new ReadResource().readJson(rte);
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
System.out.println(result);
}
}
2 changes: 0 additions & 2 deletions src/test/java/com/contentstack/utils/UtilTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ public void testRenderFunction() {

@Test
public void testCustomJSONRTE() {


JSONObject rteObject = new JSONObject();
String[] keyPath = {
"rich_text_editor", "global_rich_multiple.group.rich_text_editor"
Expand Down
Loading