Skip to content

Commit 1efdd74

Browse files
committed
Escape tilde (~). In the LabKey Markdown flavor, text between single tildes (e.g., ~strikethrough~) is rendered as strikethrough.
1 parent 83729f0 commit 1efdd74

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicNotification.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.labkey.api.announcements.api.AnnouncementService;
1111
import org.labkey.api.data.Container;
1212
import org.labkey.api.data.ContainerManager;
13+
import org.labkey.api.markdown.MarkdownService;
1314
import org.labkey.api.portal.ProjectUrls;
1415
import org.labkey.api.security.User;
1516
import org.labkey.api.security.UserManager;
@@ -592,9 +593,13 @@ private static String escape(String text)
592593
{
593594
// https://www.markdownguide.org/basic-syntax/#characters-you-can-escape
594595
// 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.
596597
// 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");
598603
}
599604

600605
public static String getExperimentCopiedMessageBody(ExperimentAnnotations sourceExperiment,
@@ -715,8 +720,24 @@ public static class TestCase extends Assert
715720
public void testMarkdownEscape()
716721
{
717722
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 ☃~!@$&amp;()_+{}-=[],.#äöüÅ This is a test PanoramaPublicTest Project ☃~!@$&amp;()_+{}-=[],.#äöüÅ</p>
733+
</div>
734+
*/
735+
MarkdownService mds = MarkdownService.get();
736+
expected = """
737+
<div class=\"lk-markdown-container\"><p>PanoramaPublicTest Project ☃~!@$&amp;()_+{}-=[],.#äöüÅ This is a test PanoramaPublicTest Project ☃~!@$&amp;()_+{}-=[],.#äöüÅ</p>
738+
</div>""";
739+
String testText = "PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ This is a test PanoramaPublicTest Project ☃~!@$&()_+{}-=[],.#äöüÅ";
740+
Assert.assertEquals(expected, mds.toHtml(escape(testText)));
720741
}
721742
}
722743
}

0 commit comments

Comments
 (0)