diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 95bdda997..6326e147a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- java: [11, 17, 21, 25]
+ java: [17, 21, 25]
steps:
- name: Checkout sources
uses: actions/checkout@v7
@@ -33,7 +33,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v5
with:
- java-version: 11
+ java-version: 17
distribution: 'zulu'
- name: Build with coverage
@@ -54,7 +54,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v5
with:
- java-version: 11
+ java-version: 17
distribution: 'zulu'
- name: Android Lint checks
diff --git a/commonmark-ext-autolink/src/test/java/org/commonmark/ext/autolink/AutolinkTest.java b/commonmark-ext-autolink/src/test/java/org/commonmark/ext/autolink/AutolinkTest.java
index fb79dfd60..34e50ac3e 100644
--- a/commonmark-ext-autolink/src/test/java/org/commonmark/ext/autolink/AutolinkTest.java
+++ b/commonmark-ext-autolink/src/test/java/org/commonmark/ext/autolink/AutolinkTest.java
@@ -91,12 +91,14 @@ public void sourceSpans() {
.extensions(EXTENSIONS)
.includeSourceSpans(IncludeSourceSpans.BLOCKS_AND_INLINES)
.build();
- Node document =
- parser.parse(
- "abc\n"
- + "http://example.com/one\n"
- + "def http://example.com/two\n"
- + "ghi http://example.com/three jkl");
+ var s =
+ """
+ abc
+ http://example.com/one
+ def http://example.com/two
+ ghi http://example.com/three jkl
+ """;
+ Node document = parser.parse(s);
Paragraph paragraph = (Paragraph) document.getFirstChild();
Text abc = (Text) paragraph.getFirstChild();
diff --git a/commonmark-ext-footnotes/src/test/java/org/commonmark/ext/footnotes/FootnoteHtmlRendererTest.java b/commonmark-ext-footnotes/src/test/java/org/commonmark/ext/footnotes/FootnoteHtmlRendererTest.java
index 1a89693b4..9102083e3 100644
--- a/commonmark-ext-footnotes/src/test/java/org/commonmark/ext/footnotes/FootnoteHtmlRendererTest.java
+++ b/commonmark-ext-footnotes/src/test/java/org/commonmark/ext/footnotes/FootnoteHtmlRendererTest.java
@@ -21,15 +21,21 @@ public class FootnoteHtmlRendererTest extends RenderingTestCase {
@Test
public void testOne() {
assertRendering(
- "Test [^foo]\n\n[^foo]: note\n",
- "
Test
\n"
- + "\n");
+ """
+ Test [^foo]
+
+ [^foo]: note
+ """,
+ """
+ Test
+
+ """);
}
@Test
@@ -37,15 +43,21 @@ public void testLabelNormalization() {
// Labels match via their normalized form. For the href and IDs to match, rendering needs to
// use the label from the definition consistently.
assertRendering(
- "Test [^bar]\n\n[^BAR]: note\n",
- "Test
\n"
- + "\n");
+ """
+ Test [^bar]
+
+ [^BAR]: note
+ """,
+ """
+ Test
+
+ """);
}
@Test
@@ -55,53 +67,80 @@ public void testMultipleReferences() {
// - The same number is used when a definition is referenced multiple times
// - Multiple backrefs are rendered
assertRendering(
- "First [^foo]\n\nThen [^bar]\n\nThen [^foo] again\n\n[^bar]: b\n[^foo]: f\n",
- "First
\n"
- + "Then
\n"
- + "Then again
\n"
- + "\n");
+ """
+ First [^foo]
+
+ Then [^bar]
+
+ Then [^foo] again
+
+ [^bar]: b
+ [^foo]: f
+ """,
+ """
+ First
+ Then
+ Then again
+
+ """);
}
@Test
public void testDefinitionWithTwoParagraphs() {
// With two paragraphs, the backref should be added to the second one
assertRendering(
- "Test [^foo]\n\n[^foo]: one\n \n two\n",
- "Test
\n"
- + "\n");
+ """
+ Test [^foo]
+
+ [^foo]: one
+ \s
+ two
+ """,
+ """
+ Test
+
+ """);
}
@Test
public void testDefinitionWithList() {
assertRendering(
- "Test [^foo]\n\n[^foo]:\n - one\n - two\n",
- "Test
\n"
- + "\n");
+ """
+ Test [^foo]
+
+ [^foo]:
+ - one
+ - two
+ """,
+ """
+ Test
+
+ """);
}
// See docs on FootnoteHtmlNodeRenderer about nested footnotes.
@@ -109,18 +148,25 @@ public void testDefinitionWithList() {
@Test
public void testNestedFootnotesSimple() {
assertRendering(
- "[^foo1]\n" + "\n" + "[^foo1]: one [^foo2]\n" + "[^foo2]: two\n",
- "\n"
- + "\n");
+ """
+ [^foo1]
+
+ [^foo1]: one [^foo2]
+ [^foo2]: two
+ """,
+ """
+
+
+ """);
}
@Test
@@ -129,149 +175,196 @@ public void testNestedFootnotesOrder() {
// The reason is that the number is done based on all references in document order,
// including references in definitions. So [^bar] from the first line is first.
assertRendering(
- "[^foo]: foo [^bar]\n" + "\n" + "[^foo]\n" + "\n" + "[^bar]: bar\n",
- "\n"
- + "\n");
+ """
+ [^foo]: foo [^bar]
+
+ [^foo]
+
+ [^bar]: bar
+ """,
+ """
+
+
+ """);
}
@Test
public void testNestedFootnotesOrder2() {
assertRendering(
- "[^1]\n"
- + "\n"
- + "[^4]: four\n"
- + "[^3]: three [^4]\n"
- + "[^2]: two [^4]\n"
- + "[^1]: one [^2][^3]\n",
- "\n"
- + "\n");
+ """
+ [^1]
+
+ [^4]: four
+ [^3]: three [^4]
+ [^2]: two [^4]
+ [^1]: one [^2][^3]
+ """,
+ """
+
+
+ """);
}
@Test
public void testNestedFootnotesCycle() {
// Footnotes can contain cycles, lol.
assertRendering(
- "[^foo1]\n" + "\n" + "[^foo1]: one [^foo2]\n" + "[^foo2]: two [^foo1]\n",
- "\n"
- + "\n");
+ """
+ [^foo1]
+
+ [^foo1]: one [^foo2]
+ [^foo2]: two [^foo1]
+ """,
+ """
+
+
+ """);
}
@Test
public void testNestedFootnotesUnreferenced() {
// This should not result in any footnotes, as baz itself isn't referenced.
// But GitHub renders bar only, with a broken backref, because bar is referenced from foo.
- assertRendering("[^foo]: foo[^bar]\n" + "[^bar]: bar\n", "");
+ assertRendering(
+ """
+ [^foo]: foo[^bar]
+ [^bar]: bar
+ """,
+ "");
// And here only 1 is rendered.
assertRendering(
- "[^1]\n" + "\n" + "[^1]: one\n" + "[^foo]: foo[^bar]\n" + "[^bar]: bar\n",
- "\n"
- + "\n");
+ """
+ [^1]
+
+ [^1]: one
+ [^foo]: foo[^bar]
+ [^bar]: bar
+ """,
+ """
+
+
+ """);
}
@Test
public void testInlineFootnotes() {
assertRenderingInline(
"Test ^[inline *footnote*]",
- "Test
\n"
- + "\n");
+ """
+ Test
+
+ """);
}
@Test
public void testInlineFootnotesNested() {
assertRenderingInline(
"Test ^[inline ^[nested]]",
- "Test
\n"
- + "\n");
+ """
+ Test
+
+ """);
}
@Test
public void testInlineFootnoteWithReference() {
// This is a bit tricky because the IDs need to be unique.
assertRenderingInline(
- "Test ^[inline [^1]]\n" + "\n" + "[^1]: normal",
- "Test
\n"
- + "\n");
+ """
+ Test ^[inline [^1]]
+
+ [^1]: normal""",
+ """
+ Test
+
+ """);
}
@Test
public void testInlineFootnoteInsideDefinition() {
assertRenderingInline(
- "Test [^1]\n" + "\n" + "[^1]: Definition ^[inline]\n",
- "Test
\n"
- + "\n");
+ """
+ Test [^1]
+
+ [^1]: Definition ^[inline]
+ """,
+ """
+ Test
+
+ """);
}
@Test
@@ -279,24 +372,30 @@ public void testInlineFootnoteInsideDefinition2() {
// Tricky because of the nested inline footnote which we want to visit after foo
// (breadth-first).
assertRenderingInline(
- "Test [^1]\n" + "\n" + "[^1]: Definition ^[inline ^[nested]] ^[foo]\n",
- "Test
\n"
- + "\n");
+ """
+ Test [^1]
+
+ [^1]: Definition ^[inline ^[nested]] ^[foo]
+ """,
+ """
+ Test
+
+ """);
}
@Test
@@ -314,14 +413,16 @@ public void testRenderNodesDirectly() {
doc.appendChild(def);
var expected =
- "Test
\n"
- + "\n";
+ """
+ Test
+
+ """;
Asserts.assertRendering("", expected, RENDERER.render(doc));
}
diff --git a/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/AlertsTest.java b/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/AlertsTest.java
index 99c0e8d7a..bee8f7be2 100644
--- a/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/AlertsTest.java
+++ b/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/AlertsTest.java
@@ -59,10 +59,12 @@ public void customType() {
assertThat(renderer.render(parser.parse("> [!INFO]\n> Custom alert")))
.isEqualTo(
- "\n"
- + "
Information
\n"
- + "
Custom alert
\n"
- + "
\n");
+ """
+
+
Information
+
Custom alert
+
+ """);
}
@Test
@@ -77,23 +79,33 @@ public void multipleCustomTypes() {
var parser = Parser.builder().extensions(Set.of(extension)).build();
var renderer = HtmlRenderer.builder().extensions(Set.of(extension)).build();
- assertThat(
- renderer.render(
- parser.parse(
- "> [!INFO]\n> Info content\n\n> [!SUCCESS]\n> Success content\n\n> [!DANGER]\n> Danger content")))
+ var s =
+ """
+ > [!INFO]
+ > Info content
+
+ > [!SUCCESS]
+ > Success content
+
+ > [!DANGER]
+ > Danger content
+ """;
+ assertThat(renderer.render(parser.parse(s)))
.isEqualTo(
- "\n"
- + "
Information
\n"
- + "
Info content
\n"
- + "
\n"
- + "\n"
- + "
Success!
\n"
- + "
Success content
\n"
- + "
\n"
- + "\n"
- + "
Danger!
\n"
- + "
Danger content
\n"
- + "
\n");
+ """
+
+
Information
+
Info content
+
+
+
Success!
+
Success content
+
+
+
Danger!
+
Danger content
+
+ """);
}
@Test
@@ -103,12 +115,19 @@ public void standardTypesWithCustomConfigured() {
var parser = Parser.builder().extensions(Set.of(extension)).build();
var renderer = HtmlRenderer.builder().extensions(Set.of(extension)).build();
- assertThat(renderer.render(parser.parse("> [!NOTE]\n> Standard type")))
+ var s =
+ """
+ > [!NOTE]
+ > Standard type
+ """;
+ assertThat(renderer.render(parser.parse(s)))
.isEqualTo(
- "\n"
- + "
Note
\n"
- + "
Standard type
\n"
- + "
\n");
+ """
+
+ """);
}
@Test
@@ -118,12 +137,19 @@ public void overrideStandardTypeTitle() {
var parser = Parser.builder().extensions(Set.of(extension)).build();
var renderer = HtmlRenderer.builder().extensions(Set.of(extension)).build();
- assertThat(renderer.render(parser.parse("> [!NOTE]\n> Localized title")))
+ var s =
+ """
+ > [!NOTE]
+ > Localized title
+ """;
+ assertThat(renderer.render(parser.parse(s)))
.isEqualTo(
- "\n"
- + "
Nota
\n"
- + "
Localized title
\n"
- + "
\n");
+ """
+
+
Nota
+
Localized title
+
+ """);
}
// Custom type validation
@@ -162,33 +188,61 @@ public void overwriteStandardTypes() {
var parser = Parser.builder().extensions(Set.of(extension)).build();
var renderer = HtmlRenderer.builder().extensions(Set.of(extension)).build();
- assertThat(renderer.render(parser.parse("> [!NOTE]\n> Regular block quote")))
+ var s =
+ """
+ > [!NOTE]
+ > Regular block quote
+ """;
+ assertThat(renderer.render(parser.parse(s)))
.isEqualTo(
- "\n"
- + "[!NOTE]\n"
- + "Regular block quote
\n"
- + "
\n");
-
- assertThat(renderer.render(parser.parse("> [!TIP]\n> Regular block quote")))
+ """
+
+ [!NOTE]
+ Regular block quote
+
+ """);
+
+ s =
+ """
+ > [!TIP]
+ > Regular block quote
+ """;
+ assertThat(renderer.render(parser.parse(s)))
.isEqualTo(
- "\n"
- + "[!TIP]\n"
- + "Regular block quote
\n"
- + "
\n");
-
- assertThat(renderer.render(parser.parse("> [!IMPORTANT]\n> Alert")))
+ """
+
+ [!TIP]
+ Regular block quote
+
+ """);
+
+ s =
+ """
+ > [!IMPORTANT]
+ > Alert
+ """;
+ assertThat(renderer.render(parser.parse(s)))
.isEqualTo(
- "\n"
- + "
Important
\n"
- + "
Alert
\n"
- + "
\n");
-
- assertThat(renderer.render(parser.parse("> [!BUG]\n> Alert")))
+ """
+
+ """);
+
+ s =
+ """
+ > [!BUG]
+ > Alert
+ """;
+ assertThat(renderer.render(parser.parse(s)))
.isEqualTo(
- "\n"
- + "
Known Bug
\n"
- + "
Alert
\n"
- + "
\n");
+ """
+
+ """);
}
// Overwriting types validation
@@ -222,130 +276,198 @@ public void overwriteTypesTitleMustNotBeEmpty() {
@Test
public void customTitle() {
assertRenderingCustomTitles(
- "> [!NOTE] Custom title\n> Note with a custom title",
- "\n"
- + "
Custom title
\n"
- + "
Note with a custom title
\n"
- + "
\n");
+ """
+ > [!NOTE] Custom title
+ > Note with a custom title
+ """,
+ """
+
+
Custom title
+
Note with a custom title
+
+ """);
}
@Test
public void customTitleNoSpace() {
assertRenderingCustomTitles(
- "> [!NOTE]Custom title\n> Note with a custom title",
- "\n"
- + "
Custom title
\n"
- + "
Note with a custom title
\n"
- + "
\n");
+ """
+ > [!NOTE]Custom title
+ > Note with a custom title
+ """,
+ """
+
+
Custom title
+
Note with a custom title
+
+ """);
}
@Test
public void customTitleExtraSpace() {
assertRenderingCustomTitles(
- "> [!NOTE] Custom title \n> Note with a custom title",
- "\n"
- + "
Custom title
\n"
- + "
Note with a custom title
\n"
- + "
\n");
+ """
+ > [!NOTE] Custom title \s
+ > Note with a custom title
+ """,
+ """
+
+
Custom title
+
Note with a custom title
+
+ """);
}
@Test
public void customTitleNoHardLineBreak() {
assertRenderingCustomTitles(
- "> [!NOTE] Custom title\\\n> Note with a custom title",
- "\n"
- + "
Custom title\\
\n"
- + "
Note with a custom title
\n"
- + "
\n");
+ """
+ > [!NOTE] Custom title\\
+ > Note with a custom title
+ """,
+ """
+
+
Custom title\\
+
Note with a custom title
+
+ """);
}
@Test
public void customTitleWithComment() {
assertRenderingCustomTitles(
- "> [!NOTE] Custom title \n> Note with a custom title",
- "\n"
- + "
Custom title
\n"
- + "
Note with a custom title
\n"
- + "
\n");
+ """
+ > [!NOTE] Custom title \s
+ > Note with a custom title
+ """,
+ """
+
+
Custom title
+
Note with a custom title
+
+ """);
}
@Test
public void customTitleWithInlineFormatting() {
assertRenderingCustomTitles(
- "> [!NOTE] Custom _title with **formatting**_\n> Note with a custom title",
- "\n"
- + "
Custom title with formatting
\n"
- + "
Note with a custom title
\n"
- + "
\n");
+ """
+ > [!NOTE] Custom _title with **formatting**_
+ > Note with a custom title
+ """,
+ """
+
+
Custom title with formatting
+
Note with a custom title
+
+ """);
}
@Test
public void customTitleWithLinkAndCode() {
assertRenderingCustomTitles(
- "> [!IMPORTANT] See [docs](https://example.com) or `run()`\n> Note with a custom title",
- "\n"
- + "
See docs or run()
\n"
- + "
Note with a custom title
\n"
- + "
\n");
+ """
+ > [!IMPORTANT] See [docs](https://example.com) or `run()`
+ > Note with a custom title
+ """,
+ """
+
+
See docs or run()
+
Note with a custom title
+
+ """);
}
@Test
public void customTitleLeadingEmptyLines() {
assertRenderingCustomTitles(
- ">\n> \n> [!NOTE] Custom **title**\n> Note with a custom title",
- "\n"
- + "
Custom title
\n"
- + "
Note with a custom title
\n"
- + "
\n");
+ """
+ >
+ > \s
+ > [!NOTE] Custom **title**
+ > Note with a custom title
+ """,
+ """
+
+
Custom title
+
Note with a custom title
+
+ """);
}
@Test
public void customTitleNoOverlappingInlines() {
assertRenderingCustomTitles(
- "> [!NOTE] Custom _title with **opening `delimiters\n> Note` with** closing delimiters_",
- "\n"
- + "
Custom _title with **opening `delimiters
\n"
- + "
Note` with** closing delimiters_
\n"
- + "
\n");
+ """
+ > [!NOTE] Custom _title with **opening `delimiters
+ > Note` with** closing delimiters_
+ """,
+ """
+
+
Custom _title with **opening `delimiters
+
Note` with** closing delimiters_
+
+ """);
}
@Test
public void customTitleIgnoresBlockContent() {
assertRenderingCustomTitles(
- "> [!NOTE] ## Custom title looks like an ATX heading\n>But it's not",
- "\n"
- + "
## Custom title looks like an ATX heading
\n"
- + "
But it's not
\n"
- + "
\n");
+ """
+ > [!NOTE] ## Custom title looks like an ATX heading
+ >But it's not
+ """,
+ """
+
+
## Custom title looks like an ATX heading
+
But it's not
+
+ """);
}
@Test
public void customTitleNoBody() {
// Alerts with no body are allowed.
assertRenderingCustomTitles(
- "> [!NOTE] Custom _title_\n> \n>\n>",
- "\n"
- + "
Custom title
\n"
- + "
\n");
+ """
+ > [!NOTE] Custom _title_
+ > \s
+ >
+ >
+ """,
+ """
+
+ """);
}
@Test
public void customTitleNoBodyNoSpace() {
assertRenderingCustomTitles(
- "> [!NOTE] Custom _title_",
- "\n"
- + "
Custom title
\n"
- + "
\n");
+ """
+ > [!NOTE] Custom _title_
+ """,
+ """
+
+ """);
}
@Test
public void onlyTrailingWhitespaceIsNotCustomTitle() {
assertRenderingCustomTitles(
- "> [!NOTE] \n> Body text",
- "\n"
- + "
Note
\n"
- + "
Body text
\n"
- + "
\n");
+ """
+ > [!NOTE] \s
+ > Body text
+ """,
+ """
+
+ """);
}
// Lazy continuation
@@ -353,21 +475,31 @@ public void onlyTrailingWhitespaceIsNotCustomTitle() {
@Test
public void noLazyContinuationAfterMarker() {
assertRendering(
- "> [!NOTE]\nBody text",
- "\n"
- + "Body text
\n");
+ """
+ > [!NOTE]
+ Body text
+ """,
+ """
+
+ Body text
+ """);
}
@Test
public void noLazyContinuationAfterTitle() {
assertRenderingCustomTitles(
- "> [!NOTE] Custom title\nBody text",
- "\n"
- + "
Custom title
\n"
- + "
\n"
- + "Body text
\n");
+ """
+ > [!NOTE] Custom title
+ Body text
+ """,
+ """
+
+ Body text
+ """);
}
// Alert markers take precedence over link reference definitions
@@ -375,32 +507,53 @@ public void noLazyContinuationAfterTitle() {
@Test
public void alertTakesPrecedence() {
assertRenderingCustomTitles(
- "> [!NOTE]: https://example.com\n> Body text\n\n[!NOTE]",
- "\n"
- + "
: https://example.com
\n"
- + "
Body text
\n"
- + "
\n"
- + "[!NOTE]
\n");
+ """
+ > [!NOTE]: https://example.com
+ > Body text
+
+ [!NOTE]
+ """,
+ """
+
+
: https://example.com
+
Body text
+
+ [!NOTE]
+ """);
}
@Test
public void alertTakesPrecedenceBefore() {
assertRenderingCustomTitles(
- "> [!NOTE]\n> Body text\n\n[!NOTE]: https://example.com",
- "\n"
- + "
Note
\n"
- + "
Body text
\n"
- + "
\n");
+ """
+ > [!NOTE]
+ > Body text
+
+ [!NOTE]: https://example.com
+ """,
+ """
+
+ """);
}
@Test
public void alertTakesPrecedenceAfter() {
assertRenderingCustomTitles(
- "[!NOTE]: https://example.com\n\n> [!NOTE]\n> Body text",
- "\n"
- + "
Note
\n"
- + "
Body text
\n"
- + "
\n");
+ """
+ [!NOTE]: https://example.com
+
+ > [!NOTE]
+ > Body text
+ """,
+ """
+
+ """);
}
// Nested alerts
@@ -408,37 +561,55 @@ public void alertTakesPrecedenceAfter() {
@Test
public void noNestedAlertsByDefault() {
assertRendering(
- "> [!TIP]\n> Body\n\n- > [!TIP]\n > Nested body",
- "\n"
- + "
Tip
\n"
- + "
Body
\n"
- + "
\n"
- + "\n"
- + "- \n"
- + "
\n"
- + "[!TIP]\n"
- + "Nested body
\n"
- + "
\n"
- + " \n"
- + "
\n");
+ """
+ > [!TIP]
+ > Body
+
+ - > [!TIP]
+ > Nested body
+ """,
+ """
+
+
+ -
+
+ [!TIP]
+ Nested body
+
+
+
+ """);
}
@Test
public void noNestedAlertsByDefaultLeadingEmptyLines() {
assertRendering(
- ">\n> \n> [!TIP]\n> Body\n\n- > [!TIP]\n > Nested body",
- "\n"
- + "
Tip
\n"
- + "
Body
\n"
- + "
\n"
- + "\n"
- + "- \n"
- + "
\n"
- + "[!TIP]\n"
- + "Nested body
\n"
- + "
\n"
- + " \n"
- + "
\n");
+ """
+ >
+ > \s
+ > [!TIP]
+ > Body
+
+ - > [!TIP]
+ > Nested body
+ """,
+ """
+
+
+ -
+
+ [!TIP]
+ Nested body
+
+
+
+ """);
}
@Test
@@ -448,50 +619,49 @@ public void nestedAlerts() {
var renderer = HtmlRenderer.builder().extensions(Set.of(extension)).build();
var source =
- String.join(
- "\n",
- "> [!TIP]",
- "> Tip body",
- "> > [!IMPORTANT]",
- "> > Important body",
- "",
- "- > [!NOTE]",
- " > Nested body",
- " >",
- " > 1. Ordered list body",
- " >",
- " > > [!CAUTION]",
- " > >",
- " > > Deeply nested body");
+ """
+ > [!TIP]
+ > Tip body
+ > > [!IMPORTANT]
+ > > Important body
+
+ - > [!NOTE]
+ > Nested body
+ >
+ > 1. Ordered list body
+ >
+ > > [!CAUTION]
+ > >
+ > > Deeply nested body
+ """;
var expected =
- String.join(
- "\n",
- "",
- "
Tip
",
- "
Tip body
",
- "
",
- "
Important
",
- "
Important body
",
- "
",
- "
",
- "",
- "- ",
- "
",
- "
Note
",
- "
Nested body
",
- "
",
- "- ",
- "
Ordered list body
",
- "",
- "
Caution
",
- "
Deeply nested body
",
- "
",
- " ",
- "
",
- "
",
- " ",
- "
\n");
-
+ """
+
+
Tip
+
Tip body
+
+
Important
+
Important body
+
+
+
+ -
+
+
Note
+
Nested body
+
+ -
+
Ordered list body
+
+
Caution
+
Deeply nested body
+
+
+
+
+
+
+ """;
assertThat(renderer.render(parser.parse(source))).isEqualTo(expected);
}
@@ -499,7 +669,12 @@ public void nestedAlerts() {
@Test
public void alertParsedAsAlertNode() {
- var document = PARSER.parse("> [!NOTE]\n> This is a note");
+ var document =
+ PARSER.parse(
+ """
+ > [!NOTE]
+ > This is a note
+ """);
var firstChild = document.getFirstChild();
assertThat(firstChild).isInstanceOf(Alert.class);
var alert = (Alert) firstChild;
@@ -522,7 +697,11 @@ public void customTypeParsedAsAlertNode() {
@Test
public void titleSourcePositionPreserved() {
- var source = "> [!NOTE] Custom title\n> Body text";
+ var source =
+ """
+ > [!NOTE] Custom title
+ > Body text
+ """;
var document = PARSER_CUSTOM_TITLES.parse(source);
var alert = (Alert) document.getFirstChild();
var title = (AlertTitle) alert.getFirstChild();
@@ -533,7 +712,15 @@ public void titleSourcePositionPreserved() {
@Test
public void titleSourcePositionPreservedBetweenBlocks() {
- var source = "- List\n\n> [!NOTE] Custom title\n> Body text\n\nPlain paragraph";
+ var source =
+ """
+ - List
+
+ > [!NOTE] Custom title
+ > Body text
+
+ Plain paragraph
+ """;
var document = PARSER_CUSTOM_TITLES.parse(source);
var alert = (Alert) document.getFirstChild().getNext();
var title = (AlertTitle) alert.getFirstChild();
@@ -544,7 +731,11 @@ public void titleSourcePositionPreservedBetweenBlocks() {
@Test
public void titleSourcePositionWithLeadingAndTrailingSpaces() {
- var source = "> [!NOTE] Custom title \n> Body text";
+ var source =
+ """
+ > [!NOTE] Custom title \s
+ > Body text
+ """;
var document = PARSER_CUSTOM_TITLES.parse(source);
var alert = (Alert) document.getFirstChild();
var title = (AlertTitle) alert.getFirstChild();
@@ -555,7 +746,11 @@ public void titleSourcePositionWithLeadingAndTrailingSpaces() {
@Test
public void titleWithInlineFormattingSourcePosition() {
- var source = "> [!NOTE] Custom _title_\n> Body text";
+ var source =
+ """
+ > [!NOTE] Custom _title_
+ > Body text
+ """;
var document = PARSER_CUSTOM_TITLES.parse(source);
var alert = (Alert) document.getFirstChild();
var title = (AlertTitle) alert.getFirstChild();
@@ -583,7 +778,11 @@ public void titleWithInlineFormattingSourcePosition() {
@Test
public void titleWithNestedInlineFormattingSourcePosition() {
- var source = "> [!NOTE] Text with **bold _and italic_**\n> Body text";
+ var source =
+ """
+ > [!NOTE] Text with **bold _and italic_**
+ > Body text
+ """;
var document = PARSER_CUSTOM_TITLES.parse(source);
var alert = (Alert) document.getFirstChild();
var title = (AlertTitle) alert.getFirstChild();
diff --git a/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/examples/AlertsExample.java b/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/examples/AlertsExample.java
index 26b348016..15ef46c9c 100644
--- a/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/examples/AlertsExample.java
+++ b/commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/examples/AlertsExample.java
@@ -25,17 +25,24 @@ private static void standardTypesExample() {
var renderer = HtmlRenderer.builder().extensions(List.of(extension)).build();
var markdown =
- "# GFM Alerts Demo\n\n"
- + "> [!NOTE]\n"
- + "> Highlights information that users should take into account.\n\n"
- + "> [!TIP]\n"
- + "> Helpful advice for doing things better.\n\n"
- + "> [!IMPORTANT]\n"
- + "> Key information users need to know.\n\n"
- + "> [!WARNING]\n"
- + "> Urgent info that needs immediate attention.\n\n"
- + "> [!CAUTION]\n"
- + "> Advises about risks or negative outcomes.\n";
+ """
+ # GFM Alerts Demo
+
+ > [!NOTE]
+ > Highlights information that users should take into account.
+
+ > [!TIP]
+ > Helpful advice for doing things better.
+
+ > [!IMPORTANT]
+ > Key information users need to know.
+
+ > [!WARNING]
+ > Urgent info that needs immediate attention.
+
+ > [!CAUTION]
+ > Advises about risks or negative outcomes.
+ """;
var html = renderer.render(parser.parse(markdown));
@@ -56,13 +63,18 @@ private static void customTypesExample() {
var renderer = HtmlRenderer.builder().extensions(List.of(extension)).build();
var markdown =
- "# Custom Alert Types\n\n"
- + "> [!NOTE]\n"
- + "> Useful information that users should know.\n\n"
- + "> [!TIP]\n"
- + "> Helpful advice for doing things better.\n\n"
- + "> [!BUG]\n"
- + "> This feature has a known issue with large files (see #42).\n";
+ """
+ # Custom Alert Types
+
+ > [!NOTE]
+ > Useful information that users should know.
+
+ > [!TIP]
+ > Helpful advice for doing things better.
+
+ > [!BUG]
+ > This feature has a known issue with large files (see #42).
+ """;
var html = renderer.render(parser.parse(markdown));
diff --git a/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java b/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java
index 5ddee95b6..7621660f9 100644
--- a/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java
+++ b/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java
@@ -30,238 +30,405 @@ public void mustHaveHeaderAndSeparator() {
@Test
public void separatorMustBeOneOrMore() {
assertRendering(
- "Abc|Def\n-|-",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "
\n");
- assertRendering(
- "Abc|Def\n--|--",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ -|-
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ --|--
+ """,
+ """
+
+ """);
}
@Test
public void separatorMustNotContainInvalidChars() {
- assertRendering("Abc|Def\n |-a-|---", "Abc|Def\n|-a-|---
\n");
- assertRendering("Abc|Def\n |:--a|---", "Abc|Def\n|:--a|---
\n");
- assertRendering("Abc|Def\n |:--a--:|---", "Abc|Def\n|:--a--:|---
\n");
+ assertRendering(
+ """
+ Abc|Def
+ |-a-|---
+ """,
+ """
+ Abc|Def
+ |-a-|---
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ |:--a|---
+ """,
+ """
+ Abc|Def
+ |:--a|---
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ |:--a--:|---
+ """,
+ """
+ Abc|Def
+ |:--a--:|---
+ """);
}
@Test
public void separatorCanHaveLeadingSpaceThenPipe() {
assertRendering(
- "Abc|Def\n |---|---",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ |---|---
+ """,
+ """
+
+ """);
}
@Test
public void separatorCanNotHaveAdjacentPipes() {
- assertRendering("Abc|Def\n---||---", "Abc|Def\n---||---
\n");
+ assertRendering(
+ """
+ Abc|Def
+ ---||---
+ """,
+ """
+ Abc|Def
+ ---||---
+ """);
}
@Test
public void separatorNeedsPipes() {
- assertRendering("Abc|Def\n|--- ---", "Abc|Def\n|--- ---
\n");
+ assertRendering(
+ """
+ Abc|Def
+ |--- ---
+ """,
+ """
+ Abc|Def
+ |--- ---
+ """);
}
@Test
public void oneHeadNoBody() {
assertRendering(
- "Abc|Def\n---|---",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ ---|---
+ """,
+ """
+
+ """);
}
@Test
public void oneColumnOneHeadNoBody() {
String expected =
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "
\n"
- + "\n"
- + "
\n";
- assertRendering("|Abc\n|---\n", expected);
- assertRendering("|Abc|\n|---|\n", expected);
- assertRendering("Abc|\n---|\n", expected);
+ """
+
+ """;
+ assertRendering(
+ """
+ |Abc
+ |---
+ """,
+ expected);
+ assertRendering(
+ """
+ |Abc|
+ |---|
+ """,
+ expected);
+ assertRendering(
+ """
+ Abc|
+ ---|
+ """,
+ expected);
// Pipe required on separator
- assertRendering("|Abc\n---\n", "|Abc
\n");
+ assertRendering(
+ """
+ |Abc
+ ---
+ """,
+ """
+ |Abc
+ """);
// Pipe required on head
- assertRendering("Abc\n|---\n", "Abc\n|---
\n");
+ assertRendering(
+ """
+ Abc
+ |---
+ """,
+ """
+ Abc
+ |---
+ """);
}
@Test
public void oneColumnOneHeadOneBody() {
String expected =
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "
\n"
- + "\n"
- + "
\n";
- assertRendering("|Abc\n|---\n|1", expected);
- assertRendering("|Abc|\n|---|\n|1|", expected);
- assertRendering("Abc|\n---|\n1|", expected);
+ """
+
+
+
+ | Abc |
+
+
+
+
+ | 1 |
+
+
+
+ """;
+ assertRendering(
+ """
+ |Abc
+ |---
+ |1
+ """,
+ expected);
+ assertRendering(
+ """
+ |Abc|
+ |---|
+ |1|
+ """,
+ expected);
+ assertRendering(
+ """
+ Abc|
+ ---|
+ 1|
+ """,
+ expected);
// Pipe required on separator
- assertRendering("|Abc\n---\n|1", "|Abc
\n|1
\n");
+ assertRendering(
+ """
+ |Abc
+ ---
+ |1
+ """,
+ """
+ |Abc
+ |1
+ """);
}
@Test
public void oneHeadOneBody() {
assertRendering(
- "Abc|Def\n---|---\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ ---|---
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void spaceBeforeSeparator() {
assertRendering(
- " |Abc|Def|\n |---|---|\n |1|2|",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ |Abc|Def|
+ |---|---|
+ |1|2|
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void separatorMustNotHaveLessPartsThanHead() {
- assertRendering("Abc|Def|Ghi\n---|---\n1|2|3", "Abc|Def|Ghi\n---|---\n1|2|3
\n");
+ assertRendering(
+ """
+ Abc|Def|Ghi
+ ---|---
+ 1|2|3
+ """,
+ """
+ Abc|Def|Ghi
+ ---|---
+ 1|2|3
+ """);
}
@Test
public void padding() {
assertRendering(
- " Abc | Def \n --- | --- \n 1 | 2 ",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc | Def\s
+ --- | ---\s
+ 1 | 2\s
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void paddingWithCodeBlockIndentation() {
assertRendering(
- "Abc|Def\n---|---\n 1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ ---|---
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void pipesOnOutside() {
assertRendering(
- "|Abc|Def|\n|---|---|\n|1|2|",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ |Abc|Def|
+ |---|---|
+ |1|2|
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void pipesOnOutsideWhitespaceAfterHeader() {
assertRendering(
- "|Abc|Def| \n|---|---|\n|1|2|",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ |Abc|Def|\s
+ |---|---|
+ |1|2|
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
@@ -269,63 +436,81 @@ public void pipesOnOutsideZeroLengthHeaders() {
// This is literally what someone has done IRL - it helped to expose
// an issue with parsing the last header cell correctly
assertRendering(
- "||center header||\n" + "-|-------------|-\n" + "1| 2 |3",
- "\n"
- + "\n"
- + "\n"
- + " | \n"
- + "center header | \n"
- + " | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "3 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ ||center header||
+ -|-------------|-
+ 1| 2 |3
+ """,
+ """
+
+
+
+ |
+ center header |
+ |
+
+
+
+
+ | 1 |
+ 2 |
+ 3 |
+
+
+
+ """);
}
@Test
public void inlineElements() {
assertRendering(
- "*Abc*|Def\n---|---\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ *Abc*|Def
+ ---|---
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void escapedPipe() {
assertRendering(
- "Abc|Def\n---|---\n1\\|2|20",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1|2 | \n"
- + "20 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ ---|---
+ 1\\|2|20
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1|2 |
+ 20 |
+
+
+
+ """);
}
@Test
@@ -334,21 +519,27 @@ public void escapedBackslash() {
// followed by a pipe (so two cells). Instead, the `\|` is parsed as an escaped pipe first,
// so just a single cell. The inline parser then gets `1\|2` which renders as `1|2`.
assertRendering(
- "Abc|Def\n---|---\n1\\\\|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1|2 | \n"
- + " | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ ---|---
+ 1\\\\|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1|2 |
+ |
+
+
+
+ """);
}
@Test
@@ -357,421 +548,580 @@ public void escapedOther() {
// table, otherwise inline parsing is wrong. So we have to be careful where we do/don't
// consume the backslash.
assertRendering(
- "Abc|Def\n---|---\n1|\\`not code`",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "`not code` | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ ---|---
+ 1|\\`not code`
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ `not code` |
+
+
+
+ """);
}
@Test
public void backslashAtEnd() {
assertRendering(
- "Abc|Def\n---|---\n1|2\\",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2\\ | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ ---|---
+ 1|2\\
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2\\ |
+
+
+
+ """);
}
@Test
public void alignLeft() {
assertRendering(
- "Abc|Def\n:-|-\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
- assertRendering(
- "Abc|Def\n:-|-\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
- assertRendering(
- "Abc|Def\n:---|---\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ :-|-
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ :-|-
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ :---|---
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void alignRight() {
assertRendering(
- "Abc|Def\n-:|-\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
- assertRendering(
- "Abc|Def\n--:|--\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
- assertRendering(
- "Abc|Def\n---:|---\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ -:|-
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ --:|--
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ ---:|---
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void alignCenter() {
assertRendering(
- "Abc|Def\n:-:|-\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
- assertRendering(
- "Abc|Def\n:--:|--\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
- assertRendering(
- "Abc|Def\n:---:|---\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ :-:|-
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ :--:|--
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ :---:|---
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void alignCenterSecond() {
assertRendering(
- "Abc|Def\n---|:---:\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ ---|:---:
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void alignLeftWithSpaces() {
assertRendering(
- "Abc|Def\n :--- |---\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ :--- |---
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void alignmentMarkerMustBeNextToDashes() {
- assertRendering("Abc|Def\n: ---|---", "Abc|Def\n: ---|---
\n");
- assertRendering("Abc|Def\n--- :|---", "Abc|Def\n--- :|---
\n");
- assertRendering("Abc|Def\n---|: ---", "Abc|Def\n---|: ---
\n");
- assertRendering("Abc|Def\n---|--- :", "Abc|Def\n---|--- :
\n");
+ assertRendering(
+ """
+ Abc|Def
+ : ---|---
+ """,
+ """
+ Abc|Def
+ : ---|---
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ --- :|---
+ """,
+ """
+ Abc|Def
+ --- :|---
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ ---|: ---
+ """,
+ """
+ Abc|Def
+ ---|: ---
+ """);
+ assertRendering(
+ """
+ Abc|Def
+ ---|--- :
+ """,
+ """
+ Abc|Def
+ ---|--- :
+ """);
}
@Test
public void bodyCanNotHaveMoreColumnsThanHead() {
assertRendering(
- "Abc|Def\n---|---\n1|2|3",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ ---|---
+ 1|2|3
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
public void bodyWithFewerColumnsThanHeadResultsInEmptyCells() {
assertRendering(
- "Abc|Def|Ghi\n---|---|---\n1|2",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "Ghi | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + " | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def|Ghi
+ ---|---|---
+ 1|2
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+ Ghi |
+
+
+
+
+ | 1 |
+ 2 |
+ |
+
+
+
+ """);
}
@Test
public void insideBlockQuote() {
assertRendering(
- "> Abc|Def\n> ---|---\n> 1|2",
- "\n"
- + "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n"
- + "
\n");
+ """
+ > Abc|Def
+ > ---|---
+ > 1|2
+ """,
+ """
+
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+
+ """);
}
@Test
public void tableWithLazyContinuationLine() {
assertRendering(
- "Abc|Def\n---|---\n1|2\nlazy",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "| lazy | \n"
- + " | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ Abc|Def
+ ---|---
+ 1|2
+ lazy
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+ | lazy |
+ |
+
+
+
+ """);
}
@Test
public void issue142() {
assertRendering(
- "||Alveolar|Bilabial\n"
- + "|:--|:-:|:-:\n"
- + "|**Plosive**|t, d|b\n"
- + "|**Tap**|ɾ|",
- "\n"
- + "\n"
- + "\n"
- + " | \n"
- + "Alveolar | \n"
- + "Bilabial | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| Plosive | \n"
- + "t, d | \n"
- + "b | \n"
- + "
\n"
- + "\n"
- + "| Tap | \n"
- + "ɾ | \n"
- + " | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ ||Alveolar|Bilabial
+ |:--|:-:|:-:
+ |**Plosive**|t, d|b
+ |**Tap**|ɾ|""",
+ """
+
+
+
+ |
+ Alveolar |
+ Bilabial |
+
+
+
+
+ | Plosive |
+ t, d |
+ b |
+
+
+ | Tap |
+ ɾ |
+ |
+
+
+
+ """);
}
@Test
public void danglingPipe() {
assertRendering(
- "Abc|Def\n" + "---|---\n" + "1|2\n" + "|",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n"
- + "|
\n");
-
- assertRendering(
- "Abc|Def\n" + "---|---\n" + "1|2\n" + " | ",
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n"
- + "|
\n");
+ """
+ Abc|Def
+ ---|---
+ 1|2
+ |
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ |
+ """);
+
+ assertRendering(
+ """
+ Abc|Def
+ ---|---
+ 1|2
+ | \s
+ """,
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ |
+ """);
}
@Test
public void interruptsParagraph() {
assertRendering(
- "text\n" + "|a |\n" + "|---|\n" + "|b |",
- "text
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| a | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| b | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+ text
+ |a |
+ |---|
+ |b |
+ """,
+ """
+ text
+
+
+
+ | a |
+
+
+
+
+ | b |
+
+
+
+ """);
}
@Test
@@ -799,20 +1149,22 @@ public void attributeProviderIsApplied() {
String rendered = renderer.render(PARSER.parse("Abc|Def\n---|---\n1|2"));
assertThat(rendered)
.isEqualTo(
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
@@ -832,20 +1184,22 @@ public void columnWidthIsRecorded() {
String rendered = renderer.render(PARSER.parse("Abc|Def\n-----|---\n1|2"));
assertThat(rendered)
.isEqualTo(
- "\n"
- + "\n"
- + "\n"
- + "| Abc | \n"
- + "Def | \n"
- + "
\n"
- + "\n"
- + "\n"
- + "\n"
- + "| 1 | \n"
- + "2 | \n"
- + "
\n"
- + "\n"
- + "
\n");
+ """
+
+
+
+ | Abc |
+ Def |
+
+
+
+
+ | 1 |
+ 2 |
+
+
+
+ """);
}
@Test
@@ -937,7 +1291,15 @@ public void sourceSpansWhenInterrupting() {
.extensions(EXTENSIONS)
.includeSourceSpans(IncludeSourceSpans.BLOCKS_AND_INLINES)
.build();
- var document = parser.parse("a\n" + "bc\n" + "|de|\n" + "|---|\n" + "|fg|");
+ var document =
+ parser.parse(
+ """
+ a
+ bc
+ |de|
+ |---|
+ |fg|
+ """);
var paragraph = (Paragraph) document.getFirstChild();
var text = (Text) paragraph.getFirstChild();
diff --git a/commonmark-ext-heading-anchor/src/test/java/org/commonmark/ext/heading/anchor/HeadingAnchorTest.java b/commonmark-ext-heading-anchor/src/test/java/org/commonmark/ext/heading/anchor/HeadingAnchorTest.java
index 95ee2d7eb..07b281bf1 100644
--- a/commonmark-ext-heading-anchor/src/test/java/org/commonmark/ext/heading/anchor/HeadingAnchorTest.java
+++ b/commonmark-ext-heading-anchor/src/test/java/org/commonmark/ext/heading/anchor/HeadingAnchorTest.java
@@ -16,55 +16,96 @@ public class HeadingAnchorTest extends RenderingTestCase {
@Test
public void baseCaseSingleHeader() {
- assertRendering("# Heading here\n", "Heading here
\n");
+ assertRendering(
+ """
+ # Heading here
+ """,
+ """
+ Heading here
+ """);
}
@Test
public void singleHeaderWithCodeBlock() {
assertRendering(
- "Hi there\n# Heading `here`\n",
- "Hi there
\nHeading here
\n");
+ """
+ Hi there
+ # Heading `here`
+ """,
+ """
+ Hi there
+ Heading here
+ """);
}
@Test
public void duplicateHeadersMakeUniqueIds() {
assertRendering(
- "# Heading here\n# Heading here",
- "Heading here
\nHeading here
\n");
+ """
+ # Heading here
+ # Heading here
+ """,
+ """
+ Heading here
+ Heading here
+ """);
}
@Test
public void testSupplementalDiacriticalMarks() {
- assertRendering("# a\u1DC0", "a\u1DC0
\n");
+ assertRendering(
+ "# a\u1DC0",
+ """
+ a\u1DC0
+ """);
}
@Test
public void testUndertieUnicodeDisplayed() {
- assertRendering("# undertie \u203F", "undertie \u203F
\n");
+ assertRendering(
+ "# undertie \u203F",
+ """
+ undertie \u203F
+ """);
}
@Test
public void testExplicitHeaderCollision() {
assertRendering(
- "# Header\n# Header\n# Header-1",
- "\n"
- + "\n"
- + "\n");
+ """
+ # Header
+ # Header
+ # Header-1
+ """,
+ """
+
+
+
+ """);
}
@Test
public void testCaseIsIgnoredWhenComparingIds() {
assertRendering(
- "# HEADING here\n" + "# heading here",
- "HEADING here
\n"
- + "heading here
\n");
+ """
+ # HEADING here
+ # heading here
+ """,
+ """
+ HEADING here
+ heading here
+ """);
}
@Test
public void testNestedBlocks() {
assertRendering(
- "## `h` `e` **l** *l* o",
- "h e l l o
\n");
+ """
+ ## `h` `e` **l** *l* o
+ """,
+ """
+ h e l l o
+ """);
}
@Test
@@ -77,25 +118,45 @@ public void boldEmphasisCharacters() {
@Test
public void testStrongEmphasis() {
assertRendering(
- "# _**Hi there**_",
- "Hi there
\n");
+ """
+ # _**Hi there**_
+ """,
+ """
+ Hi there
+ """);
}
@Test
public void testMultipleSpacesKept() {
- assertRendering("# Hi There", "Hi There
\n");
+ assertRendering(
+ """
+ # Hi There
+ """,
+ """
+ Hi There
+ """);
}
@Test
public void testNonAsciiCharacterHeading() {
- assertRendering("# bär", "bär
\n");
+ assertRendering(
+ """
+ # bär
+ """,
+ """
+ bär
+ """);
}
@Test
public void testCombiningDiaeresis() {
assertRendering(
- "# Product\u036D\u036B",
- "Product\u036D\u036B
\n");
+ """
+ # Product\u036D\u036B
+ """,
+ """
+ Product\u036D\u036B
+ """);
}
@Override
diff --git a/commonmark-ext-task-list-items/src/test/java/org/commonmark/ext/task/list/items/TaskListItemsTest.java b/commonmark-ext-task-list-items/src/test/java/org/commonmark/ext/task/list/items/TaskListItemsTest.java
index dd9290b6e..ff74c0d66 100644
--- a/commonmark-ext-task-list-items/src/test/java/org/commonmark/ext/task/list/items/TaskListItemsTest.java
+++ b/commonmark-ext-task-list-items/src/test/java/org/commonmark/ext/task/list/items/TaskListItemsTest.java
@@ -20,110 +20,253 @@ public class TaskListItemsTest extends RenderingTestCase {
@Test
public void baseCase() {
assertRendering(
- "- [x] this is *done*\n",
- "\n- " + HTML_CHECKED + " this is done
\n
\n");
+ """
+ - [x] this is *done*
+ """,
+ """
+
+ """
+ .formatted(HTML_CHECKED));
assertRendering(
- "- [ ] do this\n", "\n- " + HTML_UNCHECKED + " do this
\n
\n");
+ """
+ - [ ] do this
+ """,
+ """
+
+ """
+ .formatted(HTML_UNCHECKED));
assertRendering(
- "- [x] foo\n" + " - [ ] bar\n" + " - [x] baz\n" + "- [ ] bim",
- "\n"
- + "- "
- + HTML_CHECKED
- + " foo\n"
- + "
\n"
- + "- "
- + HTML_UNCHECKED
- + " bar
\n"
- + "- "
- + HTML_CHECKED
- + " baz
\n"
- + "
\n"
- + " \n"
- + "- "
- + HTML_UNCHECKED
- + " bim
\n"
- + "
\n");
+ """
+ - [x] foo
+ - [ ] bar
+ - [x] baz
+ - [ ] bim
+ """,
+ """
+
+ """
+ .formatted(HTML_CHECKED, HTML_UNCHECKED, HTML_CHECKED, HTML_UNCHECKED));
assertRendering(
- "* [ ] do this\n* [ ] and this",
- "\n- "
- + HTML_UNCHECKED
- + " do this
\n- "
- + HTML_UNCHECKED
- + " and this
\n
\n");
+ """
+ * [ ] do this
+ * [ ] and this
+ """,
+ """
+
+ - %s do this
+ - %s and this
+
+ """
+ .formatted(HTML_UNCHECKED, HTML_UNCHECKED));
assertRendering(
- "+ [x] one\n" + " - [ ] two\n" + " * [x] three\n",
- "\n"
- + "- "
- + HTML_CHECKED
- + " one\n"
- + "
\n"
- + "- "
- + HTML_UNCHECKED
- + " two\n"
- + "
\n"
- + "- "
- + HTML_CHECKED
- + " three
\n"
- + "
\n"
- + " \n"
- + "
\n"
- + " \n"
- + "
\n");
+ """
+ + [x] one
+ - [ ] two
+ * [x] three
+ """,
+ """
+
+ """
+ .formatted(HTML_CHECKED, HTML_UNCHECKED, HTML_CHECKED));
assertRendering(
- "TODO list\n"
- + "---------\n"
- + "- [ ] first task\n"
- + "- [x] second task\n"
- + "- [ ] third task\n\n"
- + "Let me know when you are finished",
- "TODO list
\n"
- + "\n"
- + "- "
- + HTML_UNCHECKED
- + " first task
\n"
- + "- "
- + HTML_CHECKED
- + " second task
\n"
- + "- "
- + HTML_UNCHECKED
- + " third task
\n"
- + "
\n"
- + "Let me know when you are finished
\n");
+ """
+ TODO list
+ ---------
+ - [ ] first task
+ - [x] second task
+ - [ ] third task
+
+ Let me know when you are finished
+ """,
+ """
+ TODO list
+
+ - %s first task
+ - %s second task
+ - %s third task
+
+ Let me know when you are finished
+ """
+ .formatted(HTML_UNCHECKED, HTML_CHECKED, HTML_UNCHECKED));
}
@Test
public void notListItem() {
- assertRendering("[x] this is not a task\n", "[x] this is not a task
\n");
assertRendering(
- " [ ] this is not a task either\n", "[ ] this is not a task either
\n");
+ """
+ [x] this is not a task
+ """,
+ """
+ [x] this is not a task
+ """);
+ assertRendering(
+ """
+ [ ] this is not a task either
+ """,
+ """
+ [ ] this is not a task either
+ """);
}
@Test
public void notValidTaskFormat() {
- assertRendering("- [x]no space\n", "\n");
- assertRendering(
- "- [O] is not a _task_\n", "\n");
- assertRendering("* [] neither is this\n", "\n");
- assertRendering(
- "* [ ] nor this\n" + "* [XX] nor this\n",
- "\n- [ ] nor this
\n- [XX] nor this
\n
\n");
- assertRendering("+ [x]] is not a task\n", "\n");
- assertRendering("- [x isn't\n", "\n");
- assertRendering("- [[x is not\n", "\n");
- assertRendering("- x] nope\n", "\n");
- assertRendering("- x]] no way\n", "\n");
- assertRendering("+ (x) sorry no\n", "\n");
- assertRendering("+ {x} sorry not sorry\n", "\n");
- assertRendering("+ [[x]] nooo\n", "\n");
- assertRendering(
- "+ text before [x] is not a task\n",
- "\n- text before [x] is not a task
\n
\n");
- assertRendering("* [x] \n* [ ] \n", "\n");
+ assertRendering(
+ """
+ - [x]no space
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ - [O] is not a _task_
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ * [] neither is this
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ * [ ] nor this
+ * [XX] nor this
+ """,
+ """
+
+ - [ ] nor this
+ - [XX] nor this
+
+ """);
+ assertRendering(
+ """
+ + [x]] is not a task
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ - [x isn't
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ - [[x is not
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ - x] nope
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ - x]] no way
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ + (x) sorry no
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ + {x} sorry not sorry
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ + [[x]] nooo
+ """,
+ """
+
+ """);
+ assertRendering(
+ """
+ + text before [x] is not a task
+ """,
+ """
+
+ - text before [x] is not a task
+
+ """);
+ assertRendering(
+ """
+ * [x] \s
+ * [ ] \s
+ """,
+ """
+
+ """);
}
@Override
diff --git a/commonmark-ext-yaml-front-matter/src/test/java/org/commonmark/ext/front/matter/YamlFrontMatterDataTest.java b/commonmark-ext-yaml-front-matter/src/test/java/org/commonmark/ext/front/matter/YamlFrontMatterDataTest.java
index 6ead2c48b..6493ba716 100644
--- a/commonmark-ext-yaml-front-matter/src/test/java/org/commonmark/ext/front/matter/YamlFrontMatterDataTest.java
+++ b/commonmark-ext-yaml-front-matter/src/test/java/org/commonmark/ext/front/matter/YamlFrontMatterDataTest.java
@@ -20,7 +20,13 @@ Set getExtensions() {
@Test
public void simpleValue() {
- final String input = "---" + "\nhello: world" + "\n..." + "\n" + "\ngreat";
+ final String input =
+ """
+ ---
+ hello: world
+ ...
+
+ great""";
final String rendered = "great
\n";
Map> data = getFrontMatterData(input);
@@ -35,7 +41,13 @@ public void simpleValue() {
@Test
public void emptyValue() {
- final String input = "---" + "\nkey:" + "\n---" + "\n" + "\ngreat";
+ final String input =
+ """
+ ---
+ key:
+ ---
+
+ great""";
final String rendered = "great
\n";
Map> data = getFrontMatterData(input);
@@ -50,7 +62,15 @@ public void emptyValue() {
@Test
public void listValues() {
final String input =
- "---" + "\nlist:" + "\n - value1" + "\n - value2" + "\n..." + "\n" + "\ngreat";
+ """
+ ---
+ list:
+ - value1
+ - value2
+ ...
+
+ great
+ """;
final String rendered = "great
\n";
Map> data = getFrontMatterData(input);
@@ -67,13 +87,15 @@ public void listValues() {
@Test
public void literalValue1() {
final String input =
- "---"
- + "\nliteral: |"
- + "\n hello markdown!"
- + "\n literal thing..."
- + "\n---"
- + "\n"
- + "\ngreat";
+ """
+ ---
+ literal: |
+ hello markdown!
+ literal thing...
+ ---
+
+ great
+ """;
final String rendered = "great
\n";
Map> data = getFrontMatterData(input);
@@ -89,7 +111,14 @@ public void literalValue1() {
@Test
public void literalValue2() {
final String input =
- "---" + "\nliteral: |" + "\n - hello markdown!" + "\n---" + "\n" + "\ngreat";
+ """
+ ---
+ literal: |
+ - hello markdown!
+ ---
+
+ great
+ """;
final String rendered = "great
\n";
Map> data = getFrontMatterData(input);
@@ -105,17 +134,19 @@ public void literalValue2() {
@Test
public void complexValues() {
final String input =
- "---"
- + "\nsimple: value"
- + "\nliteral: |"
- + "\n hello markdown!"
- + "\n"
- + "\n literal literal"
- + "\nlist:"
- + "\n - value1"
- + "\n - value2"
- + "\n---"
- + "\ngreat";
+ """
+ ---
+ simple: value
+ literal: |
+ hello markdown!
+
+ literal literal
+ list:
+ - value1
+ - value2
+ ---
+ great
+ """;
final String rendered = "great
\n";
Map> data = getFrontMatterData(input);
@@ -140,7 +171,12 @@ public void complexValues() {
@Test
public void empty() {
- final String input = "---\n" + "---\n" + "test";
+ final String input =
+ """
+ ---
+ ---
+ test
+ """;
final String rendered = "test
\n";
Map> data = getFrontMatterData(input);
@@ -153,9 +189,20 @@ public void empty() {
@Test
public void yamlInParagraph() {
final String input =
- "# hello\n" + "\nhello markdown world!" + "\n---" + "\nhello: world" + "\n---";
+ """
+ # hello
+
+ hello markdown world!
+ ---
+ hello: world
+ ---
+ """;
final String rendered =
- "hello
\nhello markdown world!
\nhello: world
\n";
+ """
+ hello
+ hello markdown world!
+ hello: world
+ """;
Map> data = getFrontMatterData(input);
@@ -166,8 +213,20 @@ public void yamlInParagraph() {
@Test
public void yamlOnSecondLine() {
- final String input = "hello\n" + "\n---" + "\nhello: world" + "\n---";
- final String rendered = "hello
\n
\nhello: world
\n";
+ final String input =
+ """
+ hello
+
+ ---
+ hello: world
+ ---
+ """;
+ final String rendered =
+ """
+ hello
+
+ hello: world
+ """;
Map> data = getFrontMatterData(input);
@@ -178,8 +237,16 @@ public void yamlOnSecondLine() {
@Test
public void nonMatchedStartTag() {
- final String input = "----\n" + "test";
- final String rendered = "
\ntest
\n";
+ final String input =
+ """
+ ----
+ test
+ """;
+ final String rendered =
+ """
+
+ test
+ """;
Map> data = getFrontMatterData(input);
@@ -190,8 +257,22 @@ public void nonMatchedStartTag() {
@Test
public void inList() {
- final String input = "* ---\n" + " ---\n" + "test";
- final String rendered = "\ntest
\n";
+ final String input =
+ """
+ * ---
+ ---
+ test
+ """;
+ final String rendered =
+ """
+
+ test
+ """;
Map> data = getFrontMatterData(input);
@@ -202,7 +283,12 @@ public void inList() {
@Test
public void visitorIgnoresOtherCustomNodes() {
- final String input = "---" + "\nhello: world" + "\n---" + "\n";
+ final String input =
+ """
+ ---
+ hello: world
+ ---
+ """;
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = parser.parse(input);
@@ -217,7 +303,12 @@ public void visitorIgnoresOtherCustomNodes() {
@Test
public void nodesCanBeModified() {
- final String input = "---" + "\nhello: world" + "\n---" + "\n";
+ final String input =
+ """
+ ---
+ hello: world
+ ---
+ """;
Node document = parser.parse(input);
YamlFrontMatterNode node = (YamlFrontMatterNode) document.getFirstChild().getFirstChild();
@@ -235,7 +326,12 @@ public void nodesCanBeModified() {
@Test
public void dotInKeys() {
- final String input = "---" + "\nms.author: author" + "\n---" + "\n";
+ final String input =
+ """
+ ---
+ ms.author: author
+ ---
+ """;
Map> data = getFrontMatterData(input);
@@ -248,7 +344,13 @@ public void dotInKeys() {
@Test
public void singleQuotedLiterals() {
final String input =
- "---" + "\nstring: 'It''s me'" + "\nlist:" + "\n - 'I''m here'" + "\n---" + "\n";
+ """
+ ---
+ string: 'It''s me'
+ list:
+ - 'I''m here'
+ ---
+ """;
Map> data = getFrontMatterData(input);
@@ -260,12 +362,13 @@ public void singleQuotedLiterals() {
@Test
public void doubleQuotedLiteral() {
final String input =
- "---"
- + "\nstring: \"backslash: \\\\ quote: \\\"\""
- + "\nlist:"
- + "\n - \"hey\""
- + "\n---"
- + "\n";
+ """
+ ---
+ string: "backslash: \\\\ quote: \\""
+ list:
+ - "hey"
+ ---
+ """;
Map> data = getFrontMatterData(input);
diff --git a/commonmark-integration-test/src/test/java/org/commonmark/integration/ExtensionsIntegrationTest.java b/commonmark-integration-test/src/test/java/org/commonmark/integration/ExtensionsIntegrationTest.java
index 345c02d15..e3d43b430 100644
--- a/commonmark-integration-test/src/test/java/org/commonmark/integration/ExtensionsIntegrationTest.java
+++ b/commonmark-integration-test/src/test/java/org/commonmark/integration/ExtensionsIntegrationTest.java
@@ -19,16 +19,27 @@ public class ExtensionsIntegrationTest extends RenderingTestCase {
@Test
public void testImageAttributes() {
assertRendering(
- "{height=5 width=6}",
- "
\n");
+ """
+ {height=5 width=6}
+ """,
+ """
+ 
+ """);
}
@Test
public void testTaskListItems() {
assertRendering(
- "- [ ] task to do\n- [x] task done\n",
- "\n");
+ """
+ - [ ] task to do
+ - [x] task done
+ """,
+ """
+
+ """);
}
@Override
diff --git a/commonmark-integration-test/src/test/java/org/commonmark/ui/DingusApp.java b/commonmark-integration-test/src/test/java/org/commonmark/ui/DingusApp.java
index e7870f411..a72ed959c 100644
--- a/commonmark-integration-test/src/test/java/org/commonmark/ui/DingusApp.java
+++ b/commonmark-integration-test/src/test/java/org/commonmark/ui/DingusApp.java
@@ -80,10 +80,17 @@ public void changedUpdate(DocumentEvent e) {}
tabbedPane.addChangeListener(e -> updateOutput(input.getText()));
input.setText(
- "# Example\n"
- + "Enter text *here* and see how it renders on the right.\n\n"
- + "* Try\n* this\n\n"
- + "```\nor this\n```");
+ """
+ # Example
+ Enter text *here* and see how it renders on the right.
+
+ * Try
+ * this
+
+ ```
+ or this
+ ```
+ """);
updateOutput(input.getText());
frame.setLayout(new GridLayout());
diff --git a/commonmark/src/test/java/org/commonmark/test/DelimitedTest.java b/commonmark/src/test/java/org/commonmark/test/DelimitedTest.java
index 06007e4bd..bb58ab74d 100644
--- a/commonmark/src/test/java/org/commonmark/test/DelimitedTest.java
+++ b/commonmark/src/test/java/org/commonmark/test/DelimitedTest.java
@@ -13,7 +13,12 @@ public class DelimitedTest {
@Test
public void emphasisDelimiters() {
String input =
- "* *emphasis* \n" + "* **strong** \n" + "* _important_ \n" + "* __CRITICAL__ \n";
+ """
+ * *emphasis*\s
+ * **strong**\s
+ * _important_\s
+ * __CRITICAL__\s
+ """;
Parser parser = Parser.builder().build();
Node document = parser.parse(input);
diff --git a/commonmark/src/test/java/org/commonmark/test/FencedCodeBlockParserTest.java b/commonmark/src/test/java/org/commonmark/test/FencedCodeBlockParserTest.java
index a07519756..1ccd8a8db 100644
--- a/commonmark/src/test/java/org/commonmark/test/FencedCodeBlockParserTest.java
+++ b/commonmark/src/test/java/org/commonmark/test/FencedCodeBlockParserTest.java
@@ -3,7 +3,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import org.commonmark.node.FencedCodeBlock;
-import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.commonmark.testutil.RenderingTestCase;
@@ -16,7 +15,13 @@ public class FencedCodeBlockParserTest extends RenderingTestCase {
@Test
public void backtickInfo() {
- Node document = PARSER.parse("```info ~ test\ncode\n```");
+ var s =
+ """
+ ```info ~ test
+ code
+ ```
+ """;
+ var document = PARSER.parse(s);
FencedCodeBlock codeBlock = (FencedCodeBlock) document.getFirstChild();
assertThat(codeBlock.getInfo()).isEqualTo("info ~ test");
assertThat(codeBlock.getLiteral()).isEqualTo("code\n");
@@ -25,34 +30,78 @@ public void backtickInfo() {
@Test
public void backtickInfoDoesntAllowBacktick() {
assertRendering(
- "```info ` test\ncode\n```",
- "```info ` test\ncode
\n
\n");
+ """
+ ```info ` test
+ code
+ ```
+ """,
+ """
+ ```info ` test
+ code
+
+ """);
}
@Test
public void backtickAndTildeCantBeMixed() {
- assertRendering("``~`\ncode\n``~`", "~` code ~`
\n");
+ assertRendering(
+ """
+ ``~`
+ code
+ ``~`
+ """,
+ """
+ ~` code ~`
+ """);
}
@Test
public void closingCanHaveSpacesAfter() {
- assertRendering("```\ncode\n``` ", "code\n
\n");
+ assertRendering(
+ """
+ ```
+ code
+ ``` \s
+ """,
+ """
+ code
+
+ """);
}
@Test
public void closingCanNotHaveNonSpaces() {
- assertRendering("```\ncode\n``` a", "code\n``` a\n
\n");
+ assertRendering(
+ """
+ ```
+ code
+ ``` a
+ """,
+ """
+ code
+ ``` a
+
+ """);
}
@Test
public void issue151() {
assertRendering(
- "```\nthis code\n\nshould not have BRs or paragraphs in it\nok\n```",
- "this code\n"
- + "\n"
- + "should not have BRs or paragraphs in it\n"
- + "ok\n"
- + "
\n");
+ """
+ ```
+ this code
+
+ should not have BRs or paragraphs in it
+ ok
+ ```
+ """,
+ """
+ this code
+
+ should not have BRs or paragraphs in it
+ ok
+
+ """);
}
@Override
diff --git a/commonmark/src/test/java/org/commonmark/test/ListTightLooseTest.java b/commonmark/src/test/java/org/commonmark/test/ListTightLooseTest.java
index e606d467e..047508436 100644
--- a/commonmark/src/test/java/org/commonmark/test/ListTightLooseTest.java
+++ b/commonmark/src/test/java/org/commonmark/test/ListTightLooseTest.java
@@ -7,149 +7,241 @@ public class ListTightLooseTest extends CoreRenderingTestCase {
@Test
public void tight() {
assertRendering(
- "- foo\n" + "- bar\n" + "+ baz\n",
- "\n"
- + "- foo
\n"
- + "- bar
\n"
- + "
\n"
- + "\n");
+ """
+ - foo
+ - bar
+ + baz
+ """,
+ """
+
+
+ """);
}
@Test
public void loose() {
assertRendering(
- "- foo\n" + "\n" + "- bar\n" + "\n" + "\n" + "- baz\n",
- "\n"
- + "- \n"
- + "
foo
\n"
- + " \n"
- + "- \n"
- + "
bar
\n"
- + " \n"
- + "- \n"
- + "
baz
\n"
- + " \n"
- + "
\n");
+ """
+ - foo
+
+ - bar
+
+
+ - baz
+ """,
+ """
+
+ -
+
foo
+
+ -
+
bar
+
+ -
+
baz
+
+
+ """);
}
@Test
public void looseNested() {
assertRendering(
- "- foo\n" + " - bar\n" + "\n" + "\n" + " baz",
- "\n"
- + "- foo\n"
- + "
\n"
- + "- \n"
- + "
bar
\n"
- + "baz
\n"
- + " \n"
- + "
\n"
- + " \n"
- + "
\n");
+ """
+ - foo
+ - bar
+
+
+ baz
+ """,
+ """
+
+ """);
}
@Test
public void looseNested2() {
assertRendering(
- "- a\n" + " - b\n" + "\n" + " c\n" + "- d\n",
- "\n"
- + "- a\n"
- + "
\n"
- + "- \n"
- + "
b
\n"
- + "c
\n"
- + " \n"
- + "
\n"
- + " \n"
- + "- d
\n"
- + "
\n");
+ """
+ - a
+ - b
+
+ c
+ - d
+ """,
+ """
+
+ """);
}
@Test
public void looseOuter() {
assertRendering(
- "- foo\n" + " - bar\n" + "\n" + "\n" + " baz",
- "\n"
- + "- \n"
- + "
foo
\n"
- + "\n"
- + "baz
\n"
- + " \n"
- + "
\n");
+ """
+ - foo
+ - bar
+
+
+ baz
+ """,
+ """
+
+ """);
}
@Test
public void looseListItem() {
assertRendering(
- "- one\n" + "\n" + " two\n",
- "\n" + "- \n" + "
one
\n" + "two
\n" + " \n" + "
\n");
+ """
+ - one
+
+ two
+ """,
+ """
+
+ """);
}
@Test
public void tightWithBlankLineAfter() {
assertRendering(
- "- foo\n" + "- bar\n" + "\n",
- "\n" + "- foo
\n" + "- bar
\n" + "
\n");
+ """
+ - foo
+ - bar
+
+ """,
+ """
+
+ """);
}
@Test
public void tightListWithCodeBlock() {
assertRendering(
- "- a\n" + "- ```\n" + " b\n" + "\n" + "\n" + " ```\n" + "- c\n",
- "\n");
+ """
+ - a
+ - ```
+ b
+
+
+ ```
+ - c
+ """,
+ """
+
+ """);
}
@Test
public void tightListWithCodeBlock2() {
assertRendering(
- "* foo\n" + " ```\n" + " bar\n" + "\n" + " ```\n" + " baz\n",
- "\n"
- + "- foo\n"
- + "
bar\n"
- + "\n"
- + "
\n"
- + "baz \n"
- + "
\n");
+ """
+ * foo
+ ```
+ bar
+
+ ```
+ baz
+ """,
+ """
+
+ """);
}
@Test
public void looseEmptyListItem() {
assertRendering(
- "* a\n" + "*\n" + "\n" + "* c",
- "\n"
- + "- \n"
- + "
a
\n"
- + " \n"
- + "\n"
- + "- \n"
- + "
c
\n"
- + " \n"
- + "
\n");
+ """
+ * a
+ *
+
+ * c""",
+ """
+
+ """);
}
@Test
public void looseBlankLineAfterCodeBlock() {
assertRendering(
- "1. ```\n" + " foo\n" + " ```\n" + "\n" + " bar",
- "\n"
- + "- \n"
- + "
foo\n"
- + "
\n"
- + "bar
\n"
- + " \n"
- + "
\n");
+ """
+ 1. ```
+ foo
+ ```
+
+ bar
+ """,
+ """
+
+ -
+
foo
+
+ bar
+
+
+ """);
}
}
diff --git a/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java b/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java
index c3d535e72..8dcdbebe5 100644
--- a/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java
+++ b/commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java
@@ -56,69 +56,222 @@ public void indentedCodeBlockWithMixedTabsAndSpaces() {
@Test
public void tightListInBlockQuote() {
assertRendering(
- "> *\n> * a", "\n\n
\n");
+ """
+ > *
+ > * a
+ """,
+ """
+
+
+
+ """);
}
@Test
public void looseListInBlockQuote() {
// Second line in block quote is considered blank for purpose of loose list
assertRendering(
- "> *\n>\n> * a",
- "\n\n
\n");
+ """
+ > *
+ >
+ > * a
+ """,
+ """
+
+
+
+ """);
}
@Test
public void lineWithOnlySpacesAfterListBullet() {
- assertRendering("- \n \n foo\n", "\nfoo
\n");
+ assertRendering(
+ """
+ - \s
+ \s
+ foo
+ """,
+ """
+
+ foo
+ """);
}
@Test
public void listWithTwoSpacesForFirstBullet() {
// We have two spaces after the bullet, but no content. With content, the next line would be
// required
- assertRendering("* \n foo\n", "\n");
+ assertRendering(
+ """
+ * \s
+ foo
+ """,
+ """
+
+ """);
}
@Test
public void orderedListMarkerOnly() {
- assertRendering("2.", "\n\n
\n");
+ assertRendering(
+ """
+ 2.
+ """,
+ """
+
+
+
+ """);
}
@Test
public void columnIsInTabOnPreviousLine() {
assertRendering(
- "- foo\n\n\tbar\n\n# baz\n",
- "\nbaz
\n");
+ """
+ - foo
+
+ \tbar
+
+ # baz
+ """,
+ """
+
+ baz
+ """);
assertRendering(
- "- foo\n\n\tbar\n# baz\n",
- "\nbaz
\n");
+ """
+ - foo
+
+ \tbar
+ # baz
+ """,
+ """
+
+ baz
+ """);
}
@Test
public void linkLabelWithBracket() {
- assertRendering("[a[b]\n\n[a[b]: /", "[a[b]
\n[a[b]: /
\n");
- assertRendering("[a]b]\n\n[a]b]: /", "[a]b]
\n[a]b]: /
\n");
- assertRendering("[a[b]]\n\n[a[b]]: /", "[a[b]]
\n[a[b]]: /
\n");
+ assertRendering(
+ """
+ [a[b]
+
+ [a[b]: /
+ """,
+ """
+ [a[b]
+ [a[b]: /
+ """);
+ assertRendering(
+ """
+ [a]b]
+
+ [a]b]: /
+ """,
+ """
+ [a]b]
+ [a]b]: /
+ """);
+ assertRendering(
+ """
+ [a[b]]
+
+ [a[b]]: /
+ """,
+ """
+ [a[b]]
+ [a[b]]: /
+ """);
}
@Test
public void linkLabelLength() {
String label1 = "a".repeat(999);
assertRendering(
- "[foo][" + label1 + "]\n\n[" + label1 + "]: /", "foo
\n");
+ """
+ [foo][%s]
+
+ [%s]: /
+ """
+ .formatted(label1, label1),
+ """
+ foo
+ """);
assertRendering(
- "[foo][x" + label1 + "]\n\n[x" + label1 + "]: /",
- "[foo][x" + label1 + "]
\n[x" + label1 + "]: /
\n");
+ """
+ [foo][x%s]
+
+ [x%s]: /
+ """
+ .formatted(label1, label1),
+ """
+ [foo][x%s]
+ [x%s]: /
+ """
+ .formatted(label1, label1));
assertRendering(
- "[foo][\n" + label1 + "]\n\n[\n" + label1 + "]: /",
- "[foo][\n" + label1 + "]
\n[\n" + label1 + "]: /
\n");
+ """
+ [foo][
+ %s]
+
+ [
+ %s]: /
+ """
+ .formatted(label1, label1),
+ """
+ [foo][
+ %s]
+ [
+ %s]: /
+ """
+ .formatted(label1, label1));
String label2 = "a\n".repeat(499);
assertRendering(
- "[foo][" + label2 + "]\n\n[" + label2 + "]: /", "foo
\n");
+ """
+ [foo][%s]
+
+ [%s]: /
+ """
+ .formatted(label2, label2),
+ """
+ foo
+ """);
assertRendering(
- "[foo][12" + label2 + "]\n\n[12" + label2 + "]: /",
- "[foo][12" + label2 + "]
\n[12" + label2 + "]: /
\n");
+ """
+ [foo][12%s]
+
+ [12%s]: /
+ """
+ .formatted(label2, label2),
+ """
+ [foo][12%s]
+ [12%s]: /
+ """
+ .formatted(label2, label2));
}
@Test
@@ -143,9 +296,25 @@ public void linkReferenceBackslash() {
// Backslash escapes ']', so not a valid link label
assertRendering("[\\]: test", "[]: test
\n");
// Backslash is a literal, so valid
- assertRendering("[a\\b]\n\n[a\\b]: test", "a\\b
\n");
+ assertRendering(
+ """
+ [a\\b]
+
+ [a\\b]: test
+ """,
+ """
+ a\\b
+ """);
// Backslash escapes `]` but there's another `]`, valid
- assertRendering("[a\\]]\n\n[a\\]]: test", "a]
\n");
+ assertRendering(
+ """
+ [a\\]]
+
+ [a\\]]: test
+ """,
+ """
+ a]
+ """);
}
// commonmark/cmark#177
@@ -170,22 +339,29 @@ public void renderEvenRegexpProducesStackoverflow() {
@Test
public void deeplyIndentedList() {
assertRendering(
- "* one\n" + " * two\n" + " * three\n" + " * four",
- "\n"
- + "- one\n"
- + "
\n"
- + "- two\n"
- + "
\n"
- + "- three\n"
- + "\n"
- + "
\n"
- + "
\n"
- + " \n"
- + "
\n"
- + " \n"
- + "
\n");
+ """
+ * one
+ * two
+ * three
+ * four
+ """,
+ """
+
+ """);
}
@Test
@@ -193,7 +369,15 @@ public void trailingTabs() {
// The tab is not treated as 4 spaces here and so does not result in a hard line break, but
// is just preserved.
// This matches what commonmark.js did at the time of writing.
- assertRendering("a\t\nb\n", "a\t\nb
\n");
+ assertRendering(
+ """
+ a\t
+ b
+ """,
+ """
+ a\t
+ b
+ """);
}
@Test
@@ -209,36 +393,67 @@ public void unicodePunctuationEmphasis() {
@Test
public void htmlBlockInterruptingList() {
assertRendering(
- "- \n",
- "\n"
- + "- \n"
- + "
\n"
- + "
\n");
+ """
+ -
+ """,
+ """
+
+ """);
assertRendering(
- "- \n",
- "\n"
- + "- \n"
- + "\n");
+ """
+ -
+ """,
+ """
+