<pre> content not grouped in table after conversion

Hello all,

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.
I think it should look somewhat like this:

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

For now I am using this transformation to fix this:

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

Seems like a bug, would be great to report it in jira at XWiki Rendering - XWiki.org JIRA

Thx

Should the workaround Java code be included in the Jira issue?

I have included the workaround, you can remove it if not needed :slight_smile:

https://jira.xwiki.org/browse/XRENDERING-779

Always best to provide the max details :slight_smile:

Thx!

I’ve fixed the bug, knowing where to put the fix it was quite simple. The fix will be part of the next releases.

1 Like