|
10 | 10 | import org.labkey.api.announcements.api.AnnouncementService; |
11 | 11 | import org.labkey.api.data.Container; |
12 | 12 | import org.labkey.api.data.ContainerManager; |
| 13 | +import org.labkey.api.markdown.MarkdownService; |
13 | 14 | import org.labkey.api.portal.ProjectUrls; |
14 | 15 | import org.labkey.api.security.User; |
15 | 16 | import org.labkey.api.security.UserManager; |
@@ -592,9 +593,13 @@ private static String escape(String text) |
592 | 593 | { |
593 | 594 | // https://www.markdownguide.org/basic-syntax/#characters-you-can-escape |
594 | 595 | // Escape Markdown special characters. Some character combinations can result in |
595 | | - // unintended Markdown styling, e.g. "+_Italics_+" will results in "Italics" to be italicized. |
| 596 | + // unintended Markdown styling, e.g. "+_Italics_+" will result in "Italics" to be italicized. |
596 | 597 | // This can be seen with the tricky characters used for project names in labkey tests. |
597 | | - return text.replaceAll("([`*_{}\\[\\]()#+.!|-])", "\\\\$1"); |
| 598 | + // 8/13/25 - Escape tilde (~) as well. In the LabKey Markdown flavor, text between |
| 599 | + // single tildes (e.g., ~strikethrough~) is rendered as strikethrough. |
| 600 | + // IMPORTANT: The dash (-) must be escaped in the regex or placed at the start/end of the |
| 601 | + // character class to be treated as a literal dash rather than a range operator. |
| 602 | + return text.replaceAll("([`*_{}\\[\\]()#+.!|~-])", "\\\\$1"); |
598 | 603 | } |
599 | 604 |
|
600 | 605 | public static String getExperimentCopiedMessageBody(ExperimentAnnotations sourceExperiment, |
@@ -715,8 +720,24 @@ public static class TestCase extends Assert |
715 | 720 | public void testMarkdownEscape() |
716 | 721 | { |
717 | 722 | Assert.assertEquals("\\+\\_Test\\_\\+", escape("+_Test_+")); |
718 | | - Assert.assertEquals("PanoramaPublicTest Project ☃~\\!@$&\\(\\)\\_\\+\\{\\}\\-=\\[\\],\\.\\#äöüÅ", |
719 | | - escape("PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ")); |
| 723 | + String expected = "PanoramaPublicTest Project ☃\\~\\!@$&\\(\\)\\_\\+\\{\\}\\-=\\[\\],\\.\\#äöüÅ"; |
| 724 | + String escaped = escape("PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ"); |
| 725 | + Assert.assertEquals(expected, escaped); |
| 726 | + |
| 727 | + /* |
| 728 | + PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ This is a test PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ |
| 729 | +
|
| 730 | + should be translated to |
| 731 | +
|
| 732 | + <div class="lk-markdown-container"><p>PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ This is a test PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ</p> |
| 733 | + </div> |
| 734 | + */ |
| 735 | + MarkdownService mds = MarkdownService.get(); |
| 736 | + expected = """ |
| 737 | + <div class=\"lk-markdown-container\"><p>PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ This is a test PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ</p> |
| 738 | + </div>"""; |
| 739 | + String testText = "PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ This is a test PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ"; |
| 740 | + Assert.assertEquals(expected, mds.toHtml(escape(testText))); |
720 | 741 | } |
721 | 742 | } |
722 | 743 | } |
0 commit comments