# Path: lib/robot/writer/formatters.py
# class _DataFileFormatter(object):
#     _whitespace = re.compile('\s{2,}')
#     _split_multiline_doc = True
# 
#     def __init__(self, column_count):
#         self._splitter = RowSplitter(column_count, self._split_multiline_doc)
#         self._column_count = column_count
#         self._extractor = DataExtractor(self._want_names_on_first_content_row)
# 
#     def _want_names_on_first_content_row(self, table, name):
#         return True
# 
#     def empty_row_after(self, table):
#         return self._format_row([], table)
# 
#     def format_header(self, table):
#         header = self._format_row(table.header)
#         return self._format_header(header, table)
# 
#     def format_table(self, table):
#         rows = self._extractor.rows_from_table(table)
#         if self._should_split_rows(table):
#             rows = self._split_rows(rows, table)
#         return (self._format_row(r, table) for r in rows)
# 
#     def _should_split_rows(self, table):
#         return not self._should_align_columns(table)
# 
#     def _split_rows(self, original_rows, table):
#         for original in original_rows:
#             for split in self._splitter.split(original, table.type):
#                 yield split
# 
#     def _should_align_columns(self, table):
#         return self._is_indented_table(table) and bool(table.header[1:])
# 
#     def _is_indented_table(self, table):
#         return table is not None and table.type in ['test case', 'keyword']
# 
#     def _escape_consecutive_whitespace(self, row):
#         return [self._whitespace.sub(self._whitespace_escaper,
#                                      cell.replace('\n', ' ')) for cell in row]
# 
#     def _whitespace_escaper(self, match):
#         return '\\'.join(match.group(0))
# 
#     def _format_row(self, row, table=None):
#         raise NotImplementedError
# 
#     def _format_header(self, header, table):
#         raise NotImplementedError


import re
from robot import utils
from .formatters import _DataFileFormatter

    def _is_indented_documentation_row(self, cells, table):
        return self._is_indented_table(table) and cells and \
                    cells[0] == '[Documentation]'

    def _create_indented_documentation_row(self, first_cell, cells):
        start = [first_cell, HtmlCell(cells[0])]
        if any(c.startswith('#') for c in cells):
            return start + [HtmlCell(c) for c in cells[1:]]
        return start + [DocumentationCell(cells[1], self._column_count-2)]

    def _create_first_cell(self, cell, table):
        if self._is_indented_table(table) and cell:
            return AnchorNameCell(cell, 'keyword' if table.type == 'keyword'
                                                  else 'test')
        return NameCell(cell)

    def format_header(self, table):
        if not self._should_align_columns(table) or len(table.header) == 1:
            return [HeaderCell(table.header[0], self._column_count)]
        headers = self._pad_header(table)
        return [HeaderCell(hdr) for hdr in headers]

    def _pad_header(self, table):
        header = table.header
        return header + [''] * (self._get_column_count(table) - len(header))

    def _pad(self, row, table):
        return row + [''] * (self._get_column_count(table) - len(row))


# Path: lib/robot/writer/formatters.py
# class _DataFileFormatter(object):
#     _whitespace = re.compile('\s{2,}')
#     _split_multiline_doc = True
# 
#     def __init__(self, column_count):
#         self._splitter = RowSplitter(column_count, self._split_multiline_doc)
#         self._column_count = column_count
#         self._extractor = DataExtractor(self._want_names_on_first_content_row)
# 
#     def _want_names_on_first_content_row(self, table, name):
#         return True
# 
#     def empty_row_after(self, table):
#         return self._format_row([], table)
# 
#     def format_header(self, table):
#         header = self._format_row(table.header)
#         return self._format_header(header, table)
# 
#     def format_table(self, table):
#         rows = self._extractor.rows_from_table(table)
#         if self._should_split_rows(table):
#             rows = self._split_rows(rows, table)
#         return (self._format_row(r, table) for r in rows)
# 
#     def _should_split_rows(self, table):
#         return not self._should_align_columns(table)
# 
#     def _split_rows(self, original_rows, table):
#         for original in original_rows:
#             for split in self._splitter.split(original, table.type):
#                 yield split
# 
#     def _should_align_columns(self, table):
#         return self._is_indented_table(table) and bool(table.header[1:])
# 
#     def _is_indented_table(self, table):
#         return table is not None and table.type in ['test case', 'keyword']
# 
#     def _escape_consecutive_whitespace(self, row):
#         return [self._whitespace.sub(self._whitespace_escaper,
#                                      cell.replace('\n', ' ')) for cell in row]
# 
#     def _whitespace_escaper(self, match):
#         return '\\'.join(match.group(0))
# 
#     def _format_row(self, row, table=None):
#         raise NotImplementedError
# 
#     def _format_header(self, header, table):
#         raise NotImplementedError


# Path: lib/robot/writer/htmlformatter.py
import re
from robot import utils
from .formatters import _DataFileFormatter


    def _is_indented_documentation_row(self, cells, table):
        return self._is_indented_table(table) and cells and \
                    cells[0] == '[Documentation]'

    def _create_indented_documentation_row(self, first_cell, cells):
        start = [first_cell, HtmlCell(cells[0])]
        if any(c.startswith('#') for c in cells):
            return start + [HtmlCell(c) for c in cells[1:]]
        return start + [DocumentationCell(cells[1], self._column_count-2)]

    def _create_first_cell(self, cell, table):
        if self._is_indented_table(table) and cell:
            return AnchorNameCell(cell, 'keyword' if table.type == 'keyword'
                                                  else 'test')
        return NameCell(cell)

    def format_header(self, table):
        if not self._should_align_columns(table) or len(table.header) == 1:
            return [HeaderCell(table.header[0], self._column_count)]
        headers = self._pad_header(table)
        return [HeaderCell(hdr) for hdr in headers]

    def _pad_header(self, table):
        header = table.header
        return header + [''] * (self._get_column_count(table) - len(header))

    def _pad(self, row, table):
        return row + [''] * (self._get_column_count(table) - len(row))


    def _get_column_count(self, table):