class documentation

class SimpleTableParser(TableParser): (source)

View In Hierarchy

Parse a simple table using `parse()`. Here's an example of a simple table:: ===== ===== col 1 col 2 ===== ===== 1 Second column of row 1. 2 Second column of row 2. Second line of paragraph. 3 - Second column of row 3. - Second item in bullet list (row 3, column 2). 4 is a span ------------ 5 ===== ===== Top and bottom borders use '=', column span underlines use '-', column separation is indicated with spaces. Passing the above table to the `parse()` method will result in the following data structure, whose interpretation is the same as for `GridTableParser`:: ([5, 25], [[(0, 0, 1, ['col 1']), (0, 0, 1, ['col 2'])]], [[(0, 0, 3, ['1']), (0, 0, 3, ['Second column of row 1.'])], [(0, 0, 4, ['2']), (0, 0, 4, ['Second column of row 2.', 'Second line of paragraph.'])], [(0, 0, 6, ['3']), (0, 0, 6, ['- Second column of row 3.', '', '- Second item in bullet', ' list (row 3, column 2).'])], [(0, 1, 10, ['4 is a span'])], [(0, 0, 12, ['5']), (0, 0, 12, [''])]])

Method check_columns Check for text in column margins and text overflow in the last column. Raise TableMarkupError if anything but whitespace is in column margins. Adjust the end value for the last column if there is text overflow.
Method init_row Undocumented
Method parse_columns Given a column span underline, return a list of (begin, end) pairs.
Method parse_row Given the text `lines` of a row, parse it and append to `self.table`.
Method parse_table First determine the column boundaries from the top border, then process rows. Each row may consist of multiple lines; accumulate lines until a row is complete. Call `self.parse_row` to finish the job.
Method setup Undocumented
Method structure_from_cells Undocumented
Class Variable head_body_separator_pat Matches the row separator between head rows and body rows.
Class Variable span_pat Undocumented
Instance Variable block Undocumented
Instance Variable border_end Undocumented
Instance Variable colseps Undocumented
Instance Variable columns Undocumented
Instance Variable done Undocumented
Instance Variable head_body_sep Undocumented
Instance Variable rowseps Undocumented
Instance Variable table Undocumented

Inherited from TableParser:

Method find_head_body_sep Look for a head/body row separator line; store the line index.
Method parse Analyze the text `block` and return a table data structure.
Class Variable double_width_pad_char Padding character for East Asian double-width text.
def check_columns(self, lines, first_line, columns): (source)

Check for text in column margins and text overflow in the last column. Raise TableMarkupError if anything but whitespace is in column margins. Adjust the end value for the last column if there is text overflow.

def init_row(self, colspec, offset): (source)

Undocumented

def parse_columns(self, line, offset): (source)

Given a column span underline, return a list of (begin, end) pairs.

def parse_row(self, lines, start, spanline=None): (source)

Given the text `lines` of a row, parse it and append to `self.table`. The row is parsed according to the current column spec (either `spanline` if provided or `self.columns`). For each column, extract text from each line, and check for text in column margins. Finally, adjust for insignificant whitespace.

def parse_table(self): (source)

First determine the column boundaries from the top border, then process rows. Each row may consist of multiple lines; accumulate lines until a row is complete. Call `self.parse_row` to finish the job.

def setup(self, block): (source)

Undocumented

def structure_from_cells(self): (source)

Undocumented

head_body_separator_pat = (source)

Matches the row separator between head rows and body rows.

span_pat = (source)

Undocumented

block = (source)

Undocumented

border_end = (source)

Undocumented

colseps: dict = (source)

Undocumented

columns = (source)

Undocumented

done = (source)

Undocumented

head_body_sep = (source)

Undocumented

rowseps: dict = (source)

Undocumented

table: list = (source)

Undocumented