Force markdown instead of grid format for tables with colspans (default: False)
```
-`--outdir` or `-o` specifies the output directory. The default is `out`.
-`--skip-image-conversion` or `-sic` skips the image conversion step. The default is to convert images, but this may not be necessary if the images have already been converted.
-`--force-markdown-tables` or `-mdt` forces the converter to generate markdown tables instead of grid tables. The default is to generate grid tables for tables with colspans. This option is useful to generate a first version of the table that can be manually adjusted later.
## FAQ
### The converter doesn't seem to generate image files.
...
...
@@ -60,9 +86,16 @@ Lists in table cells are also not possible. One may use html lists for this, but
```
### How to convert a table with colspans?
The converter will try to convert tables with colspans to grid tables. If the `--force-markdown-tables` option is used, then the table will be converted to a normal markdown table. If the table has colspans, then the cells will just be repeated to fill a table row.
This may not be the desired result, but markdown doesn't support colspans. A solution is to use grid tables instead.
## Changes
-**2025-01-15** - Improved handling of tables with colspans (converting them to simple grid tables). Improved error messages (added line numbers). Improved error detection for tables.
-**2024-01-09** - Added support for merging consecutive code paragraphs into a single code block.
-**2023-08-18** - Improved handling of sometimes broken inline formatting in table cells. Adding more default heading formats.
-**2023-07-27** - Added converting bold and italic text in paragraphs, headers and tables.
cells.append(f'{getTextFromXML(cell)}')# add at least a space
rows.append(cells)
nrRows+=1
# Warning if this is a single-row table
ifnrRows==1:
_print(f'[red]Single-row table found. Such tables cannot be converted to markdown.[/red] Please consider to change the following table in the original document:\n[grey39]{rows[0]}',highlight=False)
_print(f'[red]({linenumber(len(lines)+2)}) Single-row table found. Such tables cannot be converted to markdown.[/red]Consider to change the following table in the original document:\n[grey39]{rows[0]}',highlight=False)
lines.append('')# Add an empty line before a table
# Warning if a table with colspans is detected
ifcolSpanDetected:
ifforceMarkdownTables:
_print(f'[yellow]({linenumber(len(lines)+2)}) Table with colspans found: [/yellow][grey39]{richString(lastTableCaption)}[/grey39]\nConsider to convert it manually to a grid table',highlight=False)
tableLines:list[str]=[]
errorDetected:bool=False
foridx,rowinenumerate(rows):
# Check for a table caption and add separator line
ifidx==1:
lines.append('-'.join('|'*(len(row)+1)))
tableLines.append('-'.join('|'*(len(row)+1)))
# # Check if the number of columns is the same as the previous row and add cells if smaller
ifidx>0andlen(row)!=len(rows[idx-1]):
_print(f'[red]({linenumber(len(lines))}) Number of columns in table row {idx} does not match the previous row.[/red]\nTable may need extra attention',highlight=False)
errorDetected=True
# Add table row
lines.append(f'|{"|".join(row)}|'
tableLines.append(f'|{"|".join(row)}|'
.replace('\n',_linebreak))# replace line breaks in cells
# if colSpanDetected and gridTableForColspan then convert to grid table
parser.add_argument('--force-markdown-tables','-mdt',action='store_true',dest='forceMarkdownTables',help='Force markdown instead of grid format for tables with colspans')
parser.add_argument('document',nargs='+',help='documents to parse')