The grid_table_filter.rb file is a Ruby script that defines a filter for converting Pandoc-style grid tables into HTML tables with support for rowspan and colspan. Here is a summary of the key components and functionality.
## Module and Class Definitions
The script is encapsulated within the Banzai::Filter module.
The main class is GridTableFilter, which inherits from HTML::Pipeline::TextFilter.
- Regex Constants: Several regex constants are defined to match different parts of the grid table structure, such as separators and body lines.
- Helper Classes:
- Cell: Represents a cell in the table with attributes like content, rowspan, colspan, alignment, etc.
- Row: Represents a row in the table, containing an array of Cell objects.
- RowTracker: Tracks the number of rows for each column to manage rowspan.
- Helper Methods:
- separator?: Checks if a line is a separator.
- handling_content: Processes the content of a cell, handling lists and newlines.
- adjust_colspan: Adjusts the colspan of cells based on the delimiter positions.
- Main Methods:
- parse_pandoc_table_with_spans: Parses the Pandoc table, identifies headers, and processes rows to create a structured representation of the table.
- generate_html_table_with_spans: Converts the parsed table structure into an HTML table.
- call: The main entry point for the filter, which applies the regex to find grid tables and converts them to HTML.
- Error Handling: The script includes error handling to manage invalid table formats and log errors.