|
Summary: |
Verbatim block in table not grouped |
Issue Type: |
Bug |
Affects Versions: |
16.10.3 |
Assignee: |
Unassigned |
Components: |
Syntax - html/5.0 |
Created: |
20/Mar/25 15:45 |
Priority: |
Major |
Reporter: |
Armin Günther |
Description: |
When converting a HTML table like
to XWiki 2.1 syntax using the rendering API you get
The table is broken, because there is no grouping around the verbatim block. It should look somewhat like this:
I have created this transformation as a first workaround:
import org.xwiki.component.annotation.Component;
import org.xwiki.rendering.block.Block;
import org.xwiki.rendering.block.GroupBlock;
import org.xwiki.rendering.block.TableCellBlock;
import org.xwiki.rendering.block.VerbatimBlock;
import org.xwiki.rendering.internal.block.ProtectedBlockFilter;
import org.xwiki.rendering.transformation.AbstractTransformation;
import org.xwiki.rendering.transformation.TransformationContext;
import org.xwiki.rendering.transformation.TransformationException;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.List;
@Component
@Named("verbatimCell")
@Singleton
public class VerbatimBlockTableCellTransformation extends AbstractTransformation {
private final ProtectedBlockFilter filter = new ProtectedBlockFilter();
@Override
public void transform(Block block, TransformationContext transformationContext) throws TransformationException {
for (TableCellBlock cellBlock : this.filter.getChildrenByType(block, TableCellBlock.class, true)) {
for (VerbatimBlock verbatimBlock : this.filter.getChildrenByType(cellBlock, VerbatimBlock.class, false)) {
if (!verbatimBlock.isInline()) {
cellBlock.replaceChild(new GroupBlock(List.of(verbatimBlock)), verbatimBlock);
}
}
}
}
}
|
|