Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
XWiki
xwiki-rendering
Commits
5e3f2d31
Commit
5e3f2d31
authored
Apr 26, 2022
by
Vincent Massol
Browse files
XRENDERING-658: Removing the top level paragraph when it has no children fails
parent
69804ed4
Changes
3
Hide whitespace changes
Inline
Side-by-side
xwiki-rendering-api/pom.xml
View file @
5e3f2d31
...
...
@@ -32,7 +32,7 @@
<packaging>
jar
</packaging>
<description>
XWiki Rendering - Api
</description>
<properties>
<xwiki.jacoco.instructionRatio>
0.
5
</xwiki.jacoco.instructionRatio>
<xwiki.jacoco.instructionRatio>
0.
63
</xwiki.jacoco.instructionRatio>
<!-- Skipping revapi since xwiki-rendering-legacy-api wraps this module and runs checks on it -->
<xwiki.revapi.skip>
true
</xwiki.revapi.skip>
</properties>
...
...
xwiki-rendering-api/src/main/java/org/xwiki/rendering/util/ParserUtils.java
View file @
5e3f2d31
...
...
@@ -50,7 +50,9 @@ public void removeTopLevelParagraph(List<Block> blocks)
// We only remove the paragraph if there's only one top level element and if it's a paragraph.
if
((
blocks
.
size
()
==
1
)
&&
blocks
.
get
(
0
)
instanceof
ParagraphBlock
)
{
Block
paragraphBlock
=
blocks
.
remove
(
0
);
blocks
.
addAll
(
0
,
paragraphBlock
.
getChildren
());
if
(
paragraphBlock
.
getChildren
()
!=
null
)
{
blocks
.
addAll
(
0
,
paragraphBlock
.
getChildren
());
}
// Remove parent block
for
(
Block
block
:
blocks
)
{
...
...
@@ -106,13 +108,25 @@ public void convertToInline(List<Block> blocks)
// Clean top level paragraph
removeTopLevelParagraph
(
blocks
);
// Make sure included macro is inline when script macro itself is inline
Block
block
=
blocks
.
get
(
0
);
if
(
block
instanceof
MacroBlock
)
{
MacroBlock
macro
=
(
MacroBlock
)
block
;
if
(!
macro
.
isInline
())
{
blocks
.
set
(
0
,
new
MacroBlock
(
macro
.
getId
(),
macro
.
getParameters
(),
macro
.
getContent
(),
true
));
}
// Synchronize macro
if
(!
blocks
.
isEmpty
())
{
handleMacroInline
(
blocks
);
}
}
}
/**
* Make sure included macro is inline when script macro itself is inline.
*
* @param blocks the blocks to align
*/
private
void
handleMacroInline
(
List
<
Block
>
blocks
)
{
Block
block
=
blocks
.
get
(
0
);
if
(
block
instanceof
MacroBlock
)
{
MacroBlock
macro
=
(
MacroBlock
)
block
;
if
(!
macro
.
isInline
())
{
blocks
.
set
(
0
,
new
MacroBlock
(
macro
.
getId
(),
macro
.
getParameters
(),
macro
.
getContent
(),
true
));
}
}
}
...
...
xwiki-rendering-api/src/test/java/org/xwiki/rendering/util/ParserUtilsTest.java
0 → 100644
View file @
5e3f2d31
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package
org.xwiki.rendering.util
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
org.junit.jupiter.api.Test
;
import
org.xwiki.rendering.block.Block
;
import
org.xwiki.rendering.block.ParagraphBlock
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/**
* Unit tests for {@link ParserUtils}.
*
* @version $Id$
*/
class
ParserUtilsTest
{
@Test
void
convertToInlineWhenEmptyParagraph
()
{
ParserUtils
util
=
new
ParserUtils
();
List
<
Block
>
blocks
=
new
ArrayList
<>(
List
.
of
(
new
ParagraphBlock
(
Collections
.
emptyList
())));
util
.
convertToInline
(
blocks
);
assertTrue
(
blocks
.
isEmpty
());
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment