Fix: Add leading and trailing pipes to markdown tables for GFM compliance #1752
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1731 - Adds leading and trailing pipe delimiters to markdown tables for GitHub Flavored Markdown (GFM) compliance.
List of files changed and why
crawl4ai/html2text/__init__.py(lines 717-733) - Fixed table generation logic to always include boundary pipestests/test_table_gfm_compliance.py- Added 8 comprehensive unit tests to verify GFM complianceChanges
Before
After
Technical Changes
|for every cell (including first)self.o(" |")to close rows with trailing pipe---|---to| --- | --- |Why This Fix (Not
pad_tables=True)pad_tables=Falseis the default settingpad_tablesis designed for column alignment, not structural GFM compliancepad_tables=TrueandFalseHow Has This Been Tested?
Unit Tests (8 tests covering all scenarios):
test_table_has_leading_pipes- Verifies all rows start with|test_table_has_trailing_pipes- Verifies all rows end with|test_separator_row_has_pipes- Verifies separator format| --- | --- |test_works_with_pad_tables_false- Tests with default settingtest_works_with_pad_tables_true- Tests with padding enabledtest_multirow_table- Tests 4-row table with 3 columnstest_single_column_table- Tests edge casetest_empty_cells- Tests tables with empty cellsManual Testing:
All tests verify that:
pad_tablessettingsImpact
pad_tablessettingsChecklist: