Plugins for MkDocs and Python Markdown providing OpenAPI documentation, contributor tracking, timelines, cards, advanced tables, and project management features.
—
Tables with colspan and rowspan support using standard Markdown table syntax with cell-spanning notation. This Markdown extension provides enhanced table functionality, allowing cells to span multiple columns and rows while maintaining compatibility with standard Markdown table syntax.
Configure the advanced tables extension for enhanced table processing.
class SpanTableExtension(Extension):
"""
Markdown extension for tables with colspan and rowspan support.
"""
def extendMarkdown(self, md):
"""
Registers the span table processor with the Markdown parser.
Parameters:
- md: Markdown parser instance
"""
def make_extension(*args, **kwargs):
"""
Factory function for creating SpanTableExtension instances.
Returns:
SpanTableExtension: Configured extension instance
"""The extension processes ::spantable:: blocks to create advanced tables.
class SpanTableProcessor(BlockProcessor):
"""
Block processor for span tables with advanced cell spanning.
"""
START_RE: Pattern # Compiled regex for ::spantable::
END_RE: Pattern # Compiled regex for ::end-spantable::
def test(self, parent, block):
"""
Tests if block contains span table syntax.
Parameters:
- parent: Parent XML element
- block: Markdown block to test
Returns:
bool: True if block matches span table pattern
"""
def run(self, parent, blocks):
"""
Processes span table blocks and generates HTML.
Parameters:
- parent: Parent XML element
- blocks: List of Markdown blocks
"""
def find_closing_fragment_index(self, blocks) -> int:
"""
Finds the index of the closing ::end-spantable:: tag.
Parameters:
- blocks: List of Markdown blocks
Returns:
int: Index of closing tag, -1 if not found
"""
def read_first_table(self, blocks) -> Optional[SpanTable]:
"""
Extracts the first table from the given blocks.
Parameters:
- blocks: List of Markdown blocks
Returns:
Optional[SpanTable]: Parsed table or None
"""class Cell:
"""
Represents a table cell with spanning capabilities.
Attributes:
- text: Cell text content
- skip: Whether to skip rendering (used for spanned cells)
- col_span: Number of columns to span
- row_span: Number of rows to span
- col_span_defined: Whether colspan was explicitly set
- row_span_defined: Whether rowspan was explicitly set
- props: Additional HTML properties
"""
text: str
skip: bool
col_span: int
row_span: int
col_span_defined: bool
row_span_defined: bool
props: Optional[Dict[str, str]]
@property
def html_class(self) -> str:
"""
Returns CSS class string for the cell.
Returns:
str: Space-separated CSS class names
"""
class SpanTable(Table):
"""
Table with colspan and rowspan support.
Attributes:
- matrix: Table matrix structure with Cell objects
"""
matrix: Matrix
class Matrix:
"""
Represents table structure as a matrix of cells.
Attributes:
- rows: Tuple of row lists containing Cell objects
"""
rows: Tuple[List[Any], ...]
def __setitem__(self, key, value): ...
def __getitem__(self, key): ...
def __iter__(self): ...
class Table:
"""
Base table class with headers and records.
Attributes:
- headers: Table column headers
- records: Table data records
"""
headers: Tuple[str, ...]
records: Tuple[Tuple[str, ...], ...]
def items(self): ...
def __iter__(self): ...
def __len__(self): ...
def __getitem__(self, index): ...def read_table(markdown: str, cls=Table):
"""
Parses Markdown table syntax into Table objects.
Parameters:
- markdown: Markdown table content
- cls: Table class to instantiate (default: Table)
Returns:
Table instance or None if no valid table found
"""Use ::spantable:: blocks with standard Markdown table syntax:
::spantable::
| Name | Age | Location |
|---------|-----|--------------|
| John | 25 | New York |
| Jane | 30 | Los Angeles |
| Bob | 35 | Chicago |
::end-spantable::Use || to span cells across columns:
::spantable::
| Product | Q1 | Q2 | Q3 | Q4 |
|---------|----|----|----|----|
| A | 10 | 20 | 15 | 25 |
| B | 30 | Total: 90 ||
| C | 40 | 35 | 30 | 20 |
::end-spantable::Use row spanning notation for cells that span multiple rows:
::spantable::
| Category | Item | Price |
|----------|-----------|-------|
| Food ^ | Apple | $1.00 |
| | Banana | $0.50 |
| | Orange | $0.75 |
| Drinks ^ | Water | $1.50 |
| | Soda | $2.00 |
::end-spantable::::spantable:: caption="Sales Report" class="sales-table"
| Region | Q1 | Q2 | Q3 | Q4 | Total |
|---------|-------|-------|-------|-------|-------|
| North ^ | Jan | 100 | 150 | 200 | 450 |
| | Feb | 110 | 160 | 210 | |
| | Mar | 120 | 170 | 220 | |
| South | 300 | Summary ||||| 800 |
| West | 250 | 280 | 290 | 300 | 1120 |
| Total | 1050 | Grand Total |||||| 2370 |
::end-spantable::::spantable:: class="data-table" caption="Quarterly Results"
| Metric | Value | Change |
|-------------|----------|--------|
| Revenue | $1.2M | +15% |
| Profit | $300K | +22% |
| Growth Rate | Combined || |
::end-spantable::Cells can have individual CSS classes:
::spantable::
| Status | Count | Percentage |
|---------|-------|------------|
| Active | 150 | 75% |
| Pending | 30 | 15% |
| Error | 20 | 10% |
::end-spantable::| - Normal cell boundary|| - Cell spans to the next column||| - Cell spans multiple columns^ - Indicates the cell above spans down^::spantable::
| A | B spanning 2 cols || D |
| E^ | F | G | H |
| | I | J | K |
::end-spantable::This creates:
::spantable:: caption="Table Title" class="custom-class" id="table-id"Available properties:
caption: Table caption textclass: Additional CSS classesid: HTML ID attribute<div class="span-table-wrapper">
<table class="span-table custom-class" id="table-id">
<caption>Table Title</caption>
<tr>
<td colspan="2">Spanning Cell</td>
<td rowspan="2">Row Spanning Cell</td>
</tr>
<tr>
<td>Regular Cell</td>
<td>Another Cell</td>
</tr>
</table>
</div>.span-table-wrapper: Container wrapper.span-table: Table elementclass propertyStandard Markdown alignment syntax is supported:
::spantable::
| Left | Center | Right |
|:-----|:------:|------:|
| A | B | C |
::end-spantable::The wrapper div allows for responsive table styling:
.span-table-wrapper {
overflow-x: auto;
}
.span-table {
min-width: 100%;
border-collapse: collapse;
}Install with Tessl CLI
npx tessl i tessl/pypi-neoteroi-mkdocs