From a02b6d3d4af99d5eefb2daaf9c6a5c7bee9dce5e Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 12 Dec 2023 17:12:44 +0100 Subject: [PATCH 1/3] XRENDERING-667: New lines added when parsing and re-rendering groups in xwiki/2.1 * Don't print a new line when closing a group and we're already on a newline. * Add a test. --- .../src/test/resources/simple/group/group14.test | 16 ++++++++++++++++ .../src/test/resources/simple/id/id.test | 3 +-- .../xwiki20/XWikiSyntaxChainingRenderer.java | 11 +++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 xwiki-rendering-integration-tests/src/test/resources/simple/group/group14.test diff --git a/xwiki-rendering-integration-tests/src/test/resources/simple/group/group14.test b/xwiki-rendering-integration-tests/src/test/resources/simple/group/group14.test new file mode 100644 index 0000000000..d20c21e20e --- /dev/null +++ b/xwiki-rendering-integration-tests/src/test/resources/simple/group/group14.test @@ -0,0 +1,16 @@ +.#------------------------------------------------------------------- +.inputexpect|xwiki/2.0 +.# Verify that newlines in a group stay unchanged +.#------------------------------------------------------------------- +((( + + +))) +.#----------------------------------------------------- +.expect|event/1.0 +.#----------------------------------------------------- +beginDocument +beginGroup +onEmptyLines [2] +endGroup +endDocument diff --git a/xwiki-rendering-integration-tests/src/test/resources/simple/id/id.test b/xwiki-rendering-integration-tests/src/test/resources/simple/id/id.test index fca3a71a83..a4a825e2a8 100644 --- a/xwiki-rendering-integration-tests/src/test/resources/simple/id/id.test +++ b/xwiki-rendering-integration-tests/src/test/resources/simple/id/id.test @@ -23,7 +23,6 @@ endDocument .#----------------------------------------------------- (% id="idname1" %) ((( - ))) -before{{id name="idname2"/}}after \ No newline at end of file +before{{id name="idname2"/}}after diff --git a/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xwiki20/src/main/java/org/xwiki/rendering/internal/renderer/xwiki20/XWikiSyntaxChainingRenderer.java b/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xwiki20/src/main/java/org/xwiki/rendering/internal/renderer/xwiki20/XWikiSyntaxChainingRenderer.java index a83df13a46..78101b5391 100644 --- a/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xwiki20/src/main/java/org/xwiki/rendering/internal/renderer/xwiki20/XWikiSyntaxChainingRenderer.java +++ b/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xwiki20/src/main/java/org/xwiki/rendering/internal/renderer/xwiki20/XWikiSyntaxChainingRenderer.java @@ -176,7 +176,14 @@ public void endDocument(MetaData metadata) @Override public void endGroup(Map parameters) { - print("\n"); + // Flush the internal buffer to ensure we have the correct newline state. Note that the following print() + // would flush the buffer, anyway. + this.getXWikiPrinter().flush(); + + // Don't print a new line if the last element of the group is a new line. + if (!this.getXWikiPrinter().getEscapeHandler().isOnNewLine()) { + print("\n"); + } print(")))"); // Restore previous listeners that were stacked @@ -958,4 +965,4 @@ protected void popPrinter() super.popPrinter(); } -} \ No newline at end of file +} From d7433a1d4bd7d28307c2d6db0060d6fcd7985f1a Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 12 Dec 2023 17:15:54 +0100 Subject: [PATCH 2/3] XRENDERING-667: New lines added when parsing and re-rendering groups in xwiki/2.1 * Remove superfluous this. --- .../renderer/xwiki20/XWikiSyntaxChainingRenderer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xwiki20/src/main/java/org/xwiki/rendering/internal/renderer/xwiki20/XWikiSyntaxChainingRenderer.java b/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xwiki20/src/main/java/org/xwiki/rendering/internal/renderer/xwiki20/XWikiSyntaxChainingRenderer.java index 78101b5391..cce417e64d 100644 --- a/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xwiki20/src/main/java/org/xwiki/rendering/internal/renderer/xwiki20/XWikiSyntaxChainingRenderer.java +++ b/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xwiki20/src/main/java/org/xwiki/rendering/internal/renderer/xwiki20/XWikiSyntaxChainingRenderer.java @@ -178,10 +178,10 @@ public void endGroup(Map parameters) { // Flush the internal buffer to ensure we have the correct newline state. Note that the following print() // would flush the buffer, anyway. - this.getXWikiPrinter().flush(); + getXWikiPrinter().flush(); // Don't print a new line if the last element of the group is a new line. - if (!this.getXWikiPrinter().getEscapeHandler().isOnNewLine()) { + if (!getXWikiPrinter().getEscapeHandler().isOnNewLine()) { print("\n"); } print(")))"); From 244636b81866a384931df601d5b794fa64c19694 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Wed, 13 Dec 2023 10:53:35 +0100 Subject: [PATCH 3/3] XRENDERING-667: New lines added when parsing and re-rendering groups in xwiki/2.1 * Extend the test for empty lines to cover more cases. --- .../test/resources/simple/group/group14.test | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/xwiki-rendering-integration-tests/src/test/resources/simple/group/group14.test b/xwiki-rendering-integration-tests/src/test/resources/simple/group/group14.test index d20c21e20e..ff24b553e3 100644 --- a/xwiki-rendering-integration-tests/src/test/resources/simple/group/group14.test +++ b/xwiki-rendering-integration-tests/src/test/resources/simple/group/group14.test @@ -1,8 +1,24 @@ .#------------------------------------------------------------------- .inputexpect|xwiki/2.0 -.# Verify that newlines in a group stay unchanged +.# Verify that newlines in a group stay unchanged. Note that it is impossible to have a single empty line in a group. .#------------------------------------------------------------------- ((( +))) + +((( + + +))) + +((( + + + +))) + +((( + + ))) @@ -11,6 +27,14 @@ .#----------------------------------------------------- beginDocument beginGroup +endGroup +beginGroup onEmptyLines [2] endGroup +beginGroup +onEmptyLines [3] +endGroup +beginGroup +onEmptyLines [4] +endGroup endDocument