diff --git a/dotCMS/src/main/webapp/WEB-INF/velocity/VM_global_library.vm b/dotCMS/src/main/webapp/WEB-INF/velocity/VM_global_library.vm index af4f61c080ee..2bac025d9b1a 100644 --- a/dotCMS/src/main/webapp/WEB-INF/velocity/VM_global_library.vm +++ b/dotCMS/src/main/webapp/WEB-INF/velocity/VM_global_library.vm @@ -26,6 +26,12 @@ *##if ($mark.type == "underline")#* *##* *##end#* + *##if ($mark.type == "subscript")#* + *##* + *##end#* + *##if ($mark.type == "superscript")#* + *##* + *##end#* *##if ($mark.type == "link")#* *##* *##end#* + *##if ($mark.type == "subscript")#* + *##* + *##end#* + *##if ($mark.type == "superscript")#* + *##* + *##end#* *##if($mark.type == "link")#* *##* *##end#* diff --git a/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/StoryBlockMapTest.java b/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/StoryBlockMapTest.java index 764264c83daa..d96ba36e34ab 100644 --- a/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/StoryBlockMapTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/StoryBlockMapTest.java @@ -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" + @@ -79,6 +88,12 @@ public class StoryBlockMapTest extends IntegrationTestBase { " #if ($mark.type == \"underline\")\n" + " \n" + " #end\n" + + " #if ($mark.type == \"subscript\")\n" + + " \n" + + " #end\n" + + " #if ($mark.type == \"superscript\")\n" + + " \n" + + " #end\n" + " #if ($mark.type == \"link\")\n" + " \n" + " #end\n" + @@ -103,6 +118,12 @@ public class StoryBlockMapTest extends IntegrationTestBase { " #if ($mark.type == \"underline\")\n" + " \n" + " #end\n" + + " #if ($mark.type == \"subscript\")\n" + + " \n" + + " #end\n" + + " #if ($mark.type == \"superscript\")\n" + + " \n" + + " #end\n" + " #if($mark.type == \"link\")\n" + " \n" + " #end\n" + @@ -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 } / {@code } tags, and combined + * marks nest with the correct closing order (e.g. {@code bold-sup}). + */ + @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", + normalized.contains("sup")); + Assert.assertTrue(html + ": missing sub", + normalized.contains("sub")); + Assert.assertTrue(html + ": missing bold-sup", + normalized.contains("bold-sup")); + } + /** * Method to test: {@link StoryBlockMap#toHtml()} * Given Scenario: Will parse the json paragraph and render the custom html