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
4 changes: 2 additions & 2 deletions 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.5</version>
<version>1.2.6-SNAPSHOT</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 Expand Up @@ -230,7 +230,7 @@
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- <executable>${JAVA_HOME}/bin/javac</executable>-->
<!-- <executable>${JAVA_HOME}/bin/javac</executable>-->
</configuration>
</plugin>
<plugin>
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/contentstack/utils/node/NodeToHTML.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private NodeToHTML() {
*/
public static String textNodeToHTML(JSONObject nodeText, Option renderOption) {
String text = nodeText.optString("text");
text = text.replace("\n", "");
text = text.replace("\n", "<br />");
if (nodeText.has("superscript")) {
text = renderOption.renderMark(MarkType.SUPERSCRIPT, text);
}
Expand All @@ -52,7 +52,10 @@ public static String textNodeToHTML(JSONObject nodeText, Option renderOption) {
text = renderOption.renderMark(MarkType.BOLD, text);
}
if (nodeText.has("break")) {
text = renderOption.renderMark(MarkType.BREAK, text);
if (!text.contains("<br />")) {
text = renderOption.renderMark(MarkType.BREAK, text);
}
// text = renderOption.renderMark(MarkType.BREAK, text);
}
return text;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public String renderMark(MarkType markType, String text) {
case BOLD:
return "<strong>" + text + "</strong>";
case BREAK:
return "<br />" + text; // v1.2.5
return "<br />" + text.replace("\n", "");
default:
return text;
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/com/contentstack/utils/RTEResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public class RTEResult {
public static String kCodeHtml = "<code>Code template.</code>";
public static String kLinkInPHtml = "<p><strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\">LINK</a></p>";
public static String kEmbedHtml = "<iframe src=\"https://www.youtube.com/watch?v=AOP0yARiW8U\"></iframe>";
public static String kWFSAffectedHtml = "<p redactor-attributes=\"{}\" style=\"\" dir=\"ltr\"><strong>In this article:<br />\t</strong><a target=\"_self\" href=\"#Overview\">Overview</a><br />\t<a target=\"_self\" href=\"#Fulfillment\">Standard Fulfillment</a><br />\t<a target=\"_self\" href=\"#AdditionalFees\">Additional Fees</a><br />\t<a target=\"_self\" href=\"#BigBulkyFulfillment\">Big & Bulky Fulfillment</a><br />\t<a target=\"_self\" href=\"#Storage\">Storage</a><br />\t<a target=\"_self\" href=\"#ProblemInventory\">Problem Inventory</a><br />\t<a target=\"_self\" href=\"#Return\">Return Shipping & Exceptions</a><br />\t<a target=\"_self\" href=\"#DisposalRemoval\">Disposal & Removal</a><br />\t<a target=\"_self\" href=\"#AdditionalPrograms\">Additional WFS Programs</a></p><h2 redactor-attributes=\"{}\" style=\"\" id=\"Overview\" dir=\"ltr\">Overview</h2><p redactor-attributes=\"{}\" style=\"\" dir=\"ltr\">Walmart Fulfillment Services is a competitive and cost-effective solution that offers an end-to-end ecommerce fulfillment experience. Our fee structure is simple and straightforward, without signup or monthly subscription fees. You're also free to ship and store any amount of inventory you choose, without minimums or maximums. Use the <a href=\"https://marketplace.walmart.com/walmart-fulfillment-services-pricing/?_gl=1*1t4i6i1*_ga*OTkwMDc3NzQuMTY1MjM3NjY3Nw..*_ga_1LB22TM2MG*MTY1MjcyNDU5My41OS4xLjE2NTI3MjY5NzIuMA..\">WFS Calculator</a> to estimate your fulfillment and storage fees.<br /><br />The following fees are effective as of August 2023 and are subject to change.</p>";
public static String kAnchorHtml = "<p redactor-attributes=\"{}\" style=\"\" dir=\"ltr\">This is a paragraph with break true and<br />backslash nThis para has just one line break without any break key<br />Third paragraph with multiple line breaks<br /><br /><br />Fourth paragraph with multiple line breaks and break key<br /><br />Fifth paragraph with multiple only tab \t and this is text after tab<br />\tThis paragraph should start with a tab and should have a break before.</p>";
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>";

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>";
}
51 changes: 50 additions & 1 deletion src/test/java/com/contentstack/utils/TestRte.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,58 @@ public void testAvailableEntryItemTypes() {

@Test
public void testHERFID() throws IOException {
final String rte = "src/test/resources/reports/jsonviewer.json";
final String rte = "src/test/resources/reports/wfs_fees.json";
JSONObject theRTE = new ReadResource().readJson(rte);
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
Assert.assertEquals(kWFSFeesHtml, result);
}



@Test
public void testAnchorIssue() throws IOException {
final String rte = "src/test/resources/reports/anchor.json";
JSONObject theRTE = new ReadResource().readJson(rte);
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
Assert.assertEquals(kAnchorHtml, result);
}

@Test
public void testAffectedEntry() throws IOException {
final String rte = "src/test/resources/reports/wfs.json";
JSONObject theRTE = new ReadResource().readJson(rte);
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
System.out.println(result);
Assert.assertEquals(kWFSAffectedHtml, result);
}


@Test
public void testOne() throws IOException {
final String rte = "src/test/resources/reports/one.json";
JSONObject theRTE = new ReadResource().readJson(rte);
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
System.out.println(result);
Assert.assertEquals(kONEHtml, result);
}

@Test
public void testOCT7Issue() throws IOException {
final String rte = "src/test/resources/reports/oct_7.json";
JSONObject theRTE = new ReadResource().readJson(rte);
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
System.out.println(result);
// Assert.assertEquals(kONEHtml, result);
}

@Test
public void testIssueOct() throws IOException {
final String rte = "src/test/resources/reports/issue_oct.json";
JSONObject theRTE = new ReadResource().readJson(rte);
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
System.out.println(result);
// Assert.assertEquals(kONEHtml, result);
}


}
58 changes: 58 additions & 0 deletions src/test/resources/reports/anchor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"uid": "a59f9108e99747d4b3358d9e22b7c685",
"type": "doc",
"attrs": {
"dirty": true
},
"children": [
{
"type": "p",
"uid": "a3c0687b2f694bd68ec290fd92a62330",
"attrs": {
"style": {},
"redactor-attributes": {},
"dir": "ltr"
},
"children": [
{
"text": "This is a paragraph with break true and"
},
{
"text": "\n",
"break": true
},
{
"text": "backslash n"
},
{
"text": "This para has just one line break without any break key"
},
{
"text": "\n"
},
{
"text": "Third paragraph with multiple line breaks"
},
{
"text": "\n\n\n"
},
{
"text": "Fourth paragraph with multiple line breaks and break key"
},
{
"text": "\n\n",
"break": true
},
{
"text": "Fifth paragraph with multiple only tab \t and this is text after tab"
},
{
"text": "\n\t"
},
{
"text": "This paragraph should start with a tab and should have a break before."
}
]
}
]
}
Loading