Skip to content

Commit 1b49c06

Browse files
AGNT-397 edit table and elements markdown representation (#392)
1 parent 4a13a12 commit 1b49c06

21 files changed

+187
-153
lines changed

src/main/java/org/symphonyoss/symphony/messageml/markdown/nodes/TableCellNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @since 4/7/17
2626
*/
2727
public class TableCellNode extends CustomBlock {
28-
private final static String DELIMITER = " | ";
28+
private final static String DELIMITER = " ";
2929

3030
public String getDelimiter() {
3131
return DELIMITER;

src/main/java/org/symphonyoss/symphony/messageml/markdown/nodes/TableNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
* @since 4/7/17
2929
*/
3030
public class TableNode extends CustomBlock {
31-
private final static String LEAD = "Table:";
32-
private final static String DELIMITER = "---";
31+
32+
private final static String DELIMITER = " ";
3333

3434
public String getOpeningDelimiter() {
35-
return LEAD + "\n" + DELIMITER + "\n";
35+
return "\n" + DELIMITER + "\n";
3636
}
3737

3838
public String getClosingDelimiter() {

src/main/java/org/symphonyoss/symphony/messageml/markdown/nodes/form/CheckboxNode.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.symphonyoss.symphony.messageml.markdown.nodes.form;
22

3+
import org.apache.commons.lang3.StringUtils;
4+
35
/**
46
* Class that Represents a Markdown Node for the "Checkbox" form element.
57
*
@@ -8,6 +10,7 @@
810
*/
911
public class CheckboxNode extends FormElementNode {
1012
private final static String MARKDOWN = "Checkbox";
13+
private final static String CHECKBOX_DELIMITER = " ";
1114

1215
private String label;
1316

@@ -19,9 +22,19 @@ public CheckboxNode(String label) {
1922
super(MARKDOWN);
2023
this.label = label;
2124
}
22-
25+
26+
@Override
27+
public String getOpeningDelimiter() {
28+
return CHECKBOX_DELIMITER;
29+
}
30+
31+
@Override
32+
public String getClosingDelimiter() {
33+
return CHECKBOX_DELIMITER;
34+
}
35+
2336
@Override
2437
public String getText() {
25-
return (label != null) ? ":" + label : "";
38+
return StringUtils.defaultIfBlank(label, StringUtils.EMPTY);
2639
}
2740
}

src/main/java/org/symphonyoss/symphony/messageml/markdown/nodes/form/FormNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
public class FormNode extends FormElementNode {
44
private final static String MARKDOWN = "Form (log into desktop client to answer):";
5-
private final static String FORM_DELIMITER = "---";
5+
private final static String FORM_DELIMITER = " ";
66

77
public FormNode() {
88
super(MARKDOWN);
99
}
1010

1111
@Override
1212
public String getOpeningDelimiter() {
13-
return MARKDOWN + "\n" + FORM_DELIMITER + "\n";
13+
return "\n" + FORM_DELIMITER + "\n";
1414
}
1515

1616
@Override

src/main/java/org/symphonyoss/symphony/messageml/markdown/nodes/form/RadioNode.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.symphonyoss.symphony.messageml.markdown.nodes.form;
22

3+
import org.apache.commons.lang3.StringUtils;
4+
35
/**
46
* Class that Represents a Markdown Node for the "Radio" form element.
57
*
@@ -8,6 +10,7 @@
810
*/
911
public class RadioNode extends FormElementNode {
1012
private final static String MARKDOWN = "Radio Button";
13+
private final static String RADIO_DELIMITER = " ";
1114

1215
private String label;
1316

@@ -19,9 +22,19 @@ public RadioNode(String label) {
1922
super(MARKDOWN, label);
2023
this.label = label;
2124
}
25+
26+
@Override
27+
public String getOpeningDelimiter() {
28+
return RADIO_DELIMITER;
29+
}
30+
31+
@Override
32+
public String getClosingDelimiter() {
33+
return RADIO_DELIMITER;
34+
}
2235

2336
@Override
2437
public String getText() {
25-
return (label != null) ? ":" + label : "";
38+
return StringUtils.defaultIfBlank(label, StringUtils.EMPTY);
2639
}
2740
}
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.symphonyoss.symphony.messageml.markdown.nodes.form;
22

3+
import org.apache.commons.lang3.StringUtils;
4+
35
/**
46
* Class that Represents a Markdown Node for the "Select" form element.
57
*
@@ -8,7 +10,7 @@
810
*/
911
public class SelectNode extends FormElementNode implements PlaceholderLabelTooltipNode {
1012
private final static String MARKDOWN = "Dropdown";
11-
private final static String RIGHT_DELIMITER = "):";
13+
private final static String SELECT_DELIMITER = " ";
1214

1315
private String placeholder;
1416
private String label;
@@ -20,14 +22,18 @@ public SelectNode(String placeholder, String label, String tooltip) {
2022
this.label = label;
2123
this.tooltip = tooltip;
2224
}
23-
25+
26+
@Override
27+
public String getOpeningDelimiter() {
28+
return SELECT_DELIMITER;
29+
}
2430
@Override
2531
public String getClosingDelimiter() {
26-
return RIGHT_DELIMITER + "\n";
32+
return SELECT_DELIMITER + "\n";
2733
}
2834

29-
@Override
3035
public String getText() {
31-
return generateMarkdownPlaceholderLabelAndTooltip(placeholder, label, tooltip);
36+
return StringUtils.defaultIfBlank(label, StringUtils.EMPTY);
3237
}
38+
3339
}

src/test/java/org/symphonyoss/symphony/messageml/elements/TableTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public void testTable() throws Exception {
9191
assertEquals("Element attributes", Collections.emptyMap(), tfoot.getAttributes());
9292
assertEquals("Element children", 1, tfoot.getChildren().size());
9393

94-
assertEquals("Markdown", "Table:\n---\nIt | was\nthe | best\nof | times\n---\n", context.getMarkdown());
94+
assertEquals("Markdown", "\n \nIt was\nthe best\nof times\n \n",
95+
context.getMarkdown());
9596
assertEquals("EntityJSON", new ObjectNode(JsonNodeFactory.instance), context.getEntityJson());
9697
assertEquals("Legacy entities", new ObjectNode(JsonNodeFactory.instance), context.getEntities());
9798

@@ -161,11 +162,11 @@ public void testParseMarkdownWithOnlyTable() throws Exception {
161162
assertEquals("Generated PresentationML", "<div data-format=\"PresentationML\" data-version=\"2.0\">"
162163
+ "<table><tr><td>A1</td><td>B1</td></tr><tr><td>A2</td><td>B2</td></tr></table></div>",
163164
context.getPresentationML());
164-
assertEquals("Generated Markdown", "Table:\n"
165-
+ "---\n"
166-
+ "A1 | B1\n"
167-
+ "A2 | B2\n"
168-
+ "---\n",
165+
assertEquals("Generated Markdown", "\n"
166+
+ " \n"
167+
+ "A1 B1\n"
168+
+ "A2 B2\n"
169+
+ " \n",
169170
context.getMarkdown());
170171
}
171172

src/test/java/org/symphonyoss/symphony/messageml/elements/form/ButtonTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public void testNotDirectParent() throws Exception {
352352
assertNull("Button clazz attribute", button.getAttribute(CLASS_ATTR));
353353
assertEquals("Button inner text", "SELECT", button.getChild(0).asText());
354354

355-
assertEquals("Button markdown", "Form (log into desktop client to answer):\n---\n(Button:SELECT)\n\n\n---\n", context.getMarkdown());
355+
assertEquals("Button markdown", "\n \n(Button:SELECT)\n\n\n \n", context.getMarkdown());
356356
assertEquals("Button presentationML", "<div data-format=\"PresentationML\" data-version=\"2.0\"><form id=\"example\"><div><button type=\"action\" name=\"div-button\">SELECT</button></div></form></div>",
357357
context.getPresentationML());
358358
}
@@ -468,9 +468,9 @@ private String getExpectedButtonPresentation(String name, String type, String cl
468468

469469
private String getExpectedButtonMarkdown(String innerText, Boolean shouldHaveAdditionalStandardActionBtn) {
470470
if (shouldHaveAdditionalStandardActionBtn) {
471-
return "Form (log into desktop client to answer):\n---\n(Button:"+ innerText + ")\n---\n";
471+
return "\n \n(Button:" + innerText + ")\n \n";
472472
} else {
473-
return "Form (log into desktop client to answer):\n---\n(Button:"+ innerText + ")" + ACTION_BTN_MARKDOWN + "\n---\n";
473+
return "\n \n(Button:" + innerText + ")" + ACTION_BTN_MARKDOWN + "\n \n";
474474
}
475475
}
476476

src/test/java/org/symphonyoss/symphony/messageml/elements/form/CheckboxTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ public void testLabelWithUnderscoreMessageMLCheckbox() throws Exception {
172172
+ " </form>"
173173
+ " </div>", id, id);
174174
assertEquals(expectedResult, presentationML);
175-
String expectedMarkdown = " Form (log into desktop client to answer):\n" +
176-
"---\n" +
177-
" (Checkbox:Orange\\_fruit) (Button:Send) \n" +
178-
"---\n" +
175+
String expectedMarkdown = " \n" +
176+
" \n" +
177+
" Orange\\_fruit (Button:Send) \n" +
178+
" \n" +
179179
" ";
180180
assertEquals(expectedMarkdown, context.getMarkdown());
181181
}
@@ -514,8 +514,8 @@ private void verifyCheckboxMarkdown(MessageMLContext context, String label) {
514514
}
515515

516516
private String buildExpectedMarkdownForCheckbox(String label) {
517-
String expectedMarkdownText = ((label != null) ? ":" + label : "") ;
518-
return String.format("Form (log into desktop client to answer):\n---\n(Checkbox%s)%s\n---\n", expectedMarkdownText,
517+
String expectedMarkdownText = StringUtils.defaultIfBlank(label, StringUtils.EMPTY);
518+
return String.format("\n \n %s %s\n \n", expectedMarkdownText,
519519
ACTION_BTN_MARKDOWN);
520520
}
521521
}

src/test/java/org/symphonyoss/symphony/messageml/elements/form/DatePickerTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ public void testDatePickerBasic() throws Exception {
6464

6565
String presentationML = context.getPresentationML();
6666

67-
String EXPECTED_MARKDOWN = "Form (log into desktop client to answer):\n"
68-
+ "---\n"
67+
String EXPECTED_MARKDOWN = "\n"
68+
+ " \n"
6969
+ "(Date Picker:[Please pick a date])(Button:Send)\n"
70-
+ "---\n";
70+
+ " \n";
7171
String expectedPresentationML = "<div data-format=\"PresentationML\" data-version=\"2"
7272
+ ".0\"><form id=\"datepicker-form\"><input type=\"date\" name=\"date-travel\" value=\"2020-09-15\" "
7373
+ "placeholder=\"Please pick a date\" min=\"2020-09-01\" max=\"2020-09-29\" required=\"true\" "
@@ -117,10 +117,10 @@ public void testDatePickerWithLabelAndTooltip() throws Exception {
117117
Matcher matcher = pattern.matcher(presentationML);
118118
String uniqueLabelId = matcher.matches() ? matcher.group(2) : null;
119119

120-
String EXPECTED_MARKDOWN = "Form (log into desktop client to answer):\n"
121-
+ "---\n"
120+
String EXPECTED_MARKDOWN = "\n"
121+
+ " \n"
122122
+ "(Date Picker:[Departure date][This is \\n a hint][Please pick a date])(Button:Send)\n"
123-
+ "---\n";
123+
+ " \n";
124124
String expectedPresentationML = String.format("<div data-format=\"PresentationML\" "
125125
+ "data-version=\"2.0\"><form id=\"datepicker-form\"><div class=\"date-picker-group\" "
126126
+ "data-generated=\"true\"><label for=\"date-picker-%s\">Departure "
@@ -174,10 +174,10 @@ public void testDatePickerWithUnderscores() throws Exception {
174174
Matcher matcher = pattern.matcher(presentationML);
175175
String uniqueLabelId = matcher.matches() ? matcher.group(2) : null;
176176

177-
String EXPECTED_MARKDOWN = "Form (log into desktop client to answer):\n"
178-
+ "---\n"
177+
String EXPECTED_MARKDOWN = "\n"
178+
+ " \n"
179179
+ "(Date Picker:[Departure\\_date][This\\_is\\_a\\_hint][Please\\_pick\\_a\\_date])(Button:Send)\n"
180-
+ "---\n";
180+
+ " \n";
181181
String expectedPresentationML = String.format("<div data-format=\"PresentationML\" "
182182
+ "data-version=\"2.0\"><form id=\"datepicker-form\"><div class=\"date-picker-group\" "
183183
+ "data-generated=\"true\"><label for=\"date-picker-%s\">Departure_"
@@ -423,10 +423,10 @@ public void testEmptyMarkdown() throws Exception {
423423
String input = "<messageML><form id=\"" + formId + "\">"
424424
+ "<date-picker name=\"date-travel\"/>"
425425
+ ACTION_BTN_ELEMENT + "</form></messageML>";
426-
String EXPECTED_MARKDOWN = "Form (log into desktop client to answer):\n"
427-
+ "---\n"
426+
String EXPECTED_MARKDOWN = "\n"
427+
+ " \n"
428428
+ "(Date Picker)(Button:Send)\n"
429-
+ "---\n";
429+
+ " \n";
430430
context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION);
431431
assertEquals("Markdown", EXPECTED_MARKDOWN, context.getMarkdown());
432432
}
@@ -436,10 +436,10 @@ public void testPartialMarkdown() throws Exception {
436436
String input = "<messageML><form id=\"" + formId + "\">"
437437
+ "<date-picker name=\"date-travel\" placeholder=\"Please pick a date\"/>"
438438
+ ACTION_BTN_ELEMENT + "</form></messageML>";
439-
String EXPECTED_MARKDOWN = "Form (log into desktop client to answer):\n"
440-
+ "---\n"
439+
String EXPECTED_MARKDOWN = "\n"
440+
+ " \n"
441441
+ "(Date Picker:[Please pick a date])(Button:Send)\n"
442-
+ "---\n";
442+
+ " \n";
443443
context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION);
444444
assertEquals("Markdown", EXPECTED_MARKDOWN, context.getMarkdown());
445445
}

0 commit comments

Comments
 (0)