This issue has been created
 
 
XWiki Rendering / cid:jira-generated-image-avatar-05c81fdd-fe28-4ce0-8c57-2bff6700dd69 XRENDERING-779 Open

Verbatim block in table not grouped

 
View issue   ·   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-fdee4366-52ba-4ff6-80e1-5225a86742fe Armin Günther created this issue on 20/Mar/25 15:45
 
Summary: Verbatim block in table not grouped
Issue Type: cid:jira-generated-image-avatar-05c81fdd-fe28-4ce0-8c57-2bff6700dd69 Bug
Affects Versions: 16.10.3
Assignee: Unassigned
Components: Syntax - html/5.0
Created: 20/Mar/25 15:45
Priority: cid:jira-generated-image-static-major-344c192e-7fab-4b37-a6cb-da65b2861476 Major
Reporter: Armin Günther
Description:

When converting a HTML table like

<table>
  <tr>
    <td>Line continuations</td>
    <td><pre>
let example = Rx.Observable
        .combineLatest(obs1)
        .subscribe(...);</pre>
    </td>
  </tr>
  <tr>
    <td>Array Initialiser</td>
    <td>var numbers = [1, 2, 3];</td>
  </tr>
</table>

to XWiki 2.1 syntax using the rendering API you get

|Line continuations|

{{{
let example = Rx.Observable
        .combineLatest(obs1)
        .subscribe(...);}}}
|Array Initialiser|var numbers = [1, 2, 3];

The table is broken, because there is no grouping around the verbatim block.
It should look somewhat like this:

|Line continuations|(((
{{{let example = Rx.Observable
        .combineLatest(obs1)
        .subscribe(...);}}}
)))
|Array Initialiser|var numbers = [1, 2, 3];

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);
                }
            }
        }
    }
}