Uploaded image for project: 'XWiki Rendering'
  1. XWiki Rendering
  2. XRENDERING-779

Verbatim block in table not grouped

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Major
    • None
    • 16.10.3
    • Syntax - html/5.0
    • Unknown
    • N/A
    • N/A

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

      Attachments

        Issue Links

          Activity

            People

              MichaelHamann Michael Hamann
              armingu Armin Günther
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: