Skip to content

Commit

Permalink
Remove empty line after heading
Browse files Browse the repository at this point in the history
  • Loading branch information
Alf-Melmac committed Dec 21, 2023
1 parent 6880608 commit b41d6f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/java/de/webalf/slotbot/util/DiscordMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public static String toHtml(String s) {
*/
private static String replaceHeadings(String s) {
return s
.replaceAll("(?m)^###\\s(.+)(\n|$)", "<h3>$1</h3>$2")
.replaceAll("(?m)^##\\s(.+)(\n|$)", "<h2>$1</h2>$2")
.replaceAll("(?m)^#\\s(.+)(\n|$)", "<h1>$1</h1>$2");
.replaceAll("(?m)^###\\s(.+)(\n|$)", "<h3>$1</h3>")
.replaceAll("(?m)^##\\s(.+)(\n|$)", "<h2>$1</h2>")
.replaceAll("(?m)^#\\s(.+)(\n|$)", "<h1>$1</h1>");
}

private static String replace(String s, String symbol, String matcher, String tag) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/de/webalf/slotbot/util/DiscordMarkdownTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static Stream<Arguments> toHtml() {
Arguments.of("### Hello World", "<h3>Hello World</h3>", "Heading 3"),
Arguments.of("""
# Hello World
Text""", "<h1>Hello World</h1>%sText".formatted(FORMATTED_BREAK), "heading with text"),
Text""", "<h1>Hello World</h1>Text", "heading with text"),
Arguments.of("""
Text
# Hello World""", "Text%s<h1>Hello World</h1>".formatted(FORMATTED_BREAK), "text followed by heading"),
Expand All @@ -53,7 +53,7 @@ private static Stream<Arguments> toHtml() {
h2
### Heading 3
h3""", "<h1>Heading 1</h1>%1$sh1%1$s<h2>Heading 2</h2>%1$sh2%1$s%2$s\n<h3>Heading 3</h3>%1$sh3".formatted(FORMATTED_BREAK, HTML_BREAK), "headings"),
h3""", "<h1>Heading 1</h1>h1%1$s<h2>Heading 2</h2>h2%1$s%2$s\n<h3>Heading 3</h3>h3".formatted(FORMATTED_BREAK, HTML_BREAK), "headings"),
Arguments.of("Text # Hello World", "Text # Hello World", "inline heading"),
Arguments.of("Evil <script>alert('Hello World');</script> <a href=\"https://example.com\">Link</a>",
"Evil Link", "filters other html tags")
Expand Down

0 comments on commit b41d6f3

Please sign in to comment.