Skip to content
Open
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
12 changes: 12 additions & 0 deletions dotCMS/src/main/webapp/WEB-INF/velocity/VM_global_library.vm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
*##if ($mark.type == "underline")#*
*#<u>#*
*##end#*
*##if ($mark.type == "subscript")#*
*#<sub>#*
*##end#*
*##if ($mark.type == "superscript")#*
*#<sup>#*
*##end#*
*##if ($mark.type == "link")#*
*#<a href="${esc.html($mark.attrs.href)}" target="${esc.html($mark.attrs.target)}"#*
*##if($mark.attrs.title) title="${esc.html($mark.attrs.title)}"#end#*
Expand Down Expand Up @@ -54,6 +60,12 @@
*##if ($mark.type == "underline")#*
*#</u>#*
*##end#*
*##if ($mark.type == "subscript")#*
*#</sub>#*
*##end#*
*##if ($mark.type == "superscript")#*
*#</sup>#*
*##end#*
*##if($mark.type == "link")#*
*#</a>#*
*##end#*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public class StoryBlockMapTest extends IntegrationTestBase {
private static final String JSON_ULIST =
"{\"type\":\"doc\",\"content\":[{\"type\":\"bulletList\",\"content\":[{\"type\":\"listItem\",\"attrs\":{\"textAlign\":\"left\"},\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":\"left\"},\"content\":[{\"type\":\"text\",\"text\":\"1\"}]}]},{\"type\":\"listItem\",\"attrs\":{\"textAlign\":\"left\"},\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":\"left\"},\"content\":[{\"type\":\"text\",\"text\":\"2\"}]}]},{\"type\":\"listItem\",\"attrs\":{\"textAlign\":\"left\"},\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":\"left\"},\"content\":[{\"type\":\"text\",\"text\":\"3\"}]}]}]}]}";

private static final String JSON_SUB_SUP =
"{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":\"left\"},\"content\":["
+ "{\"type\":\"text\",\"marks\":[{\"type\":\"superscript\"}],\"text\":\"sup\"},"
+ "{\"type\":\"text\",\"text\":\" and \"},"
+ "{\"type\":\"text\",\"marks\":[{\"type\":\"subscript\"}],\"text\":\"sub\"},"
+ "{\"type\":\"text\",\"text\":\" and \"},"
+ "{\"type\":\"text\",\"marks\":[{\"type\":\"bold\"},{\"type\":\"superscript\"}],\"text\":\"bold-sup\"}"
+ "]}]}";

private static final String MACRO = "#macro(renderMarks $content)\n" +
"\n" +
" #if($content.marks)\n" +
Expand All @@ -79,6 +88,12 @@ public class StoryBlockMapTest extends IntegrationTestBase {
" #if ($mark.type == \"underline\")\n" +
" <u>\n" +
" #end\n" +
" #if ($mark.type == \"subscript\")\n" +
" <sub>\n" +
" #end\n" +
" #if ($mark.type == \"superscript\")\n" +
" <sup>\n" +
" #end\n" +
" #if ($mark.type == \"link\")\n" +
" <a href=\"$mark.attrs.href\" target=\"$mark.attrs.target\">\n" +
" #end\n" +
Expand All @@ -103,6 +118,12 @@ public class StoryBlockMapTest extends IntegrationTestBase {
" #if ($mark.type == \"underline\")\n" +
" </u>\n" +
" #end\n" +
" #if ($mark.type == \"subscript\")\n" +
" </sub>\n" +
" #end\n" +
" #if ($mark.type == \"superscript\")\n" +
" </sup>\n" +
" #end\n" +
" #if($mark.type == \"link\")\n" +
" </a>\n" +
" #end\n" +
Expand Down Expand Up @@ -256,6 +277,29 @@ public void test_default_render_to_html() throws JSONException {

}

/**
* Method to test: {@link StoryBlockMap#toHtml()}
* Given Scenario: A paragraph contains text with subscript, superscript, and a combined bold+superscript mark.
* ExpectedResult: The rendered HTML wraps each text run in {@code <sub>} / {@code <sup>} tags, and combined
* marks nest with the correct closing order (e.g. {@code <strong><sup>bold-sup</sup></strong>}).
*/
@Test
public void test_subscript_and_superscript_marks_render_to_html() throws JSONException {

final StoryBlockMap storyBlockMap = new StoryBlockMap(JSON_SUB_SUP);
final String html = storyBlockMap.toHtml();
// The inline MACRO registered in @Before pads tags with newlines/indent, so
// strip whitespace before asserting on contiguous mark wrappings.
final String normalized = html.replaceAll("\\s+", "");

Assert.assertTrue(html + ": missing <sup>sup</sup>",
normalized.contains("<sup>sup</sup>"));
Assert.assertTrue(html + ": missing <sub>sub</sub>",
normalized.contains("<sub>sub</sub>"));
Assert.assertTrue(html + ": missing <strong><sup>bold-sup</sup></strong>",
normalized.contains("<strong><sup>bold-sup</sup></strong>"));
}

/**
* Method to test: {@link StoryBlockMap#toHtml()}
* Given Scenario: Will parse the json paragraph and render the custom html
Expand Down
Loading