def docx_process_table(table: DOCX_TABLE_TYPE,
                       config: TextProcessingConfig) -> str:
    """
    Converts a DOCX table to text.

    Structure representing a DOCX table:

    .. code-block:: none

        table
            .rows[]
                .cells[]
                    .paragraphs[]
                        .text

    That's the structure of a :class:`docx.table.Table` object, but also of our
    homebrew creation, :class:`CustomDocxTable`.

    The ``plain`` option optimizes for natural language processing, by:

    - removing vertical lines:

      .. code-block:: none

        +-------------+-------------+
        | AAA AAA     | BBB BBB     |
        | AAA AAA     | BBB BBB     |
        +-------------+-------------+

      becomes

      .. code-block:: none

        -----------------------------
          AAA AAA       BBB BBB
          AAA AAA       BBB BBB
        -----------------------------

    - and offsetting cells:

      .. code-block:: none

        AAA AAA     BBB BBB     CCC CCC
        AAA AAA     BBB BBB     CCC CCC

      becomes

      .. code-block:: none

        AAA AAA
        AAA AAA
                    BBB BBB
                    BBB BBB
                                CCC CCC
                                CCC CCC

    - Note also that the grids in DOCX files can have varying number of cells
      per row, e.g.

      .. code-block:: none
      
            +---+---+---+
            | 1 | 2 | 3 |
            +---+---+---+
            | 1 | 2 |
            +---+---+

    """

    def get_cell_text(cell_) -> str:
        cellparagraphs = [paragraph.text.strip()
                          for paragraph in cell_.paragraphs]
        cellparagraphs = [x for x in cellparagraphs if x]
        return '\n\n'.join(cellparagraphs)

    ncols = 1
    # noinspection PyTypeChecker
    for row in table.rows:
        ncols = max(ncols, len(row.cells))
    pt = prettytable.PrettyTable(
        field_names=list(range(ncols)),
        encoding=ENCODING,
        header=False,
        border=True,
        hrules=prettytable.ALL,
        vrules=prettytable.NONE if config.plain else prettytable.ALL,
    )
    pt.align = 'l'
    pt.valign = 't'
    pt.max_width = max(config.width // ncols, config.min_col_width)
    if config.plain:
        # noinspection PyTypeChecker
        for row in table.rows:
            for i, cell in enumerate(row.cells):
                n_before = i
                n_after = ncols - i - 1
                # ... use ncols, not len(row.cells), since "cells per row" is
                #     not constant, but prettytable wants a fixed number.
                #     (changed in v0.2.8)
                ptrow = (
                    [''] * n_before +
                    [get_cell_text(cell)] +
                    [''] * n_after
                )
                assert(len(ptrow) == ncols)
                pt.add_row(ptrow)
    else:
        # noinspection PyTypeChecker
        for row in table.rows:
            ptrow = []  # type: List[str]
            # noinspection PyTypeChecker
            for cell in row.cells:
                ptrow.append(get_cell_text(cell))
            ptrow += [''] * (ncols - len(ptrow))  # added in v0.2.8
            assert (len(ptrow) == ncols)
            pt.add_row(ptrow)
    return pt.get_string()
Converts a DOCX table to text.

    Structure representing a DOCX table:

    .. code-block:: none

        table
            .rows[]
                .cells[]
                    .paragraphs[]
                        .text

    That's the structure of a :class:`docx.table.Table` object, but also of our
    homebrew creation, :class:`CustomDocxTable`.

    The ``plain`` option optimizes for natural language processing, by:

    - removing vertical lines:

      .. code-block:: none

        +-------------+-------------+
        | AAA AAA     | BBB BBB     |
        | AAA AAA     | BBB BBB     |
        +-------------+-------------+

      becomes

      .. code-block:: none

        -----------------------------
          AAA AAA       BBB BBB
          AAA AAA       BBB BBB
        -----------------------------

    - and offsetting cells:

      .. code-block:: none

        AAA AAA     BBB BBB     CCC CCC
        AAA AAA     BBB BBB     CCC CCC

      becomes

      .. code-block:: none

        AAA AAA
        AAA AAA
                    BBB BBB
                    BBB BBB
                                CCC CCC
                                CCC CCC

    - Note also that the grids in DOCX files can have varying number of cells
      per row, e.g.

      .. code-block:: none
      
            +---+---+---+
            | 1 | 2 | 3 |
            +---+---+---+
            | 1 | 2 |
            +---+---+