Commit 5e3f2d31 authored by Vincent Massol's avatar Vincent Massol
Browse files

XRENDERING-658: Removing the top level paragraph when it has no children fails

parent 69804ed4
......@@ -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>
......
......@@ -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));
}
}
}
......
/*
* 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());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment