Skip to content

Phase 7: Tables - Conversion and Rendering - #14

Open
flexseth wants to merge 6 commits into
feature/text-formattingfrom
feature/tables
Open

Phase 7: Tables - Conversion and Rendering#14
flexseth wants to merge 6 commits into
feature/text-formattingfrom
feature/tables

Conversation

@flexseth

Copy link
Copy Markdown
Owner

Summary

Implements Phase 7: Tables conversion (Markdown → WikiFormatting) and rendering (WikiFormatting → React). Converts Markdown pipe tables to WikiFormatting || syntax and renders them as proper HTML tables with styling.

Branching Strategy: Pattern 2 - Sub-branch from feature/text-formatting base branch. Will merge to text-formatting, then eventually text-formatting → trunk when all phases complete.

Phase 7a: Conversion

  • Markdown pipe tables (| col |) → WikiFormatting (|| col ||)
  • Removes separator rows (|---|)
  • Auto-bolds headers ('''Header''')
  • 34 comprehensive tests, 100% coverage

Phase 7b: Rendering

  • WikiFormatting → React <table> elements
  • Proper <thead> and <tbody> structure
  • Cell content parsed for inline formatting
  • 29 tests, Trac-like styling with dark mode

Files Changed

New Files:

  • src/converters/tables.js - Table conversion logic
  • src/converters/tables.test.js - 34 converter tests
  • src/renderers/tables.js - Table rendering functions
  • src/renderers/tables.test.js - 29 renderer tests
  • TESTING_tables.md - Manual testing document with 40+ examples

Modified Files:

  • src/converters/markdownToWiki.js - Integrated table conversion
  • src/converters/markdownToWiki.test.js - 12 integration tests
  • src/renderers/wikiToReact.js - Integrated table rendering
  • src/components/RenderedView.css - Table styling (light + dark mode)

Test Results

662 tests passing (63 new table-specific tests)

  • 34 converter unit tests
  • 29 renderer unit tests
  • 12 integration tests
  • 100% code coverage on converters and renderers
  • All previous tests still passing (no regressions)

Security Review

PASSED - No vulnerabilities identified

  • React auto-escaping active (no dangerouslySetInnerHTML)
  • Type validation with TypeError
  • Secure data flow: text → text → React elements
  • Consistent with Phases 4, 5, 6 security patterns
  • XSS test cases verified (15+ attack vectors)

Examples

Input (Markdown):

| WordPress | PHP | MySQL |
|-----------|-----|-------|
| 6.4 | **7.4+** | 5.7+ |

Column 2 (WikiFormatting):

|| '''WordPress''' || '''PHP''' || '''MySQL''' ||
|| 6.4 || '''7.4+''' || 5.7+ ||

Column 3 (Rendered):

Proper HTML table with <thead>, <tbody>, styling, and bold formatting in cells.

Testing

Manual testing file: TESTING_tables.md

  • 40+ table examples
  • Formatting in cells (bold, italic, links, code)
  • Security test cases (XSS, injection attempts)
  • WordPress real-world examples
  • Verification checklists

Implementation Notes

  • Tables processed after code block extraction, before text formatting
  • Headers auto-bolded via '''Header''' syntax
  • Cell content parsed through existing parseLinks() for security
  • Alternating row colors, responsive design, horizontal scroll for wide tables
  • Dark mode support matches existing components

Next Steps

After merge to feature/text-formatting:

  • Continue with Phase 8 (Images) or Phase 9 (Lists)
  • Or merge feature/text-formattingtrunk if ready to release tables

Checklist

  • All tests passing (662 total)
  • Security review passed
  • 100% code coverage on new code
  • JSDoc documentation complete
  • Integration tests added
  • Manual testing document created
  • Dark mode styling implemented
  • Responsive design verified
  • No regressions in existing tests
  • Correct base branch (feature/text-formatting)

🚀 Ready for review and merge to feature/text-formatting

Phase 7a: Tables Conversion (Markdown → WikiFormatting)
- Core converter: src/converters/tables.js
  - Converts Markdown pipe tables (| col |) to WikiFormatting (|| col ||)
  - Removes separator rows (|---|---|)
  - Auto-bolds headers ('''Header''')
  - Type safety with TypeError for non-string inputs
  - 100% JSDoc documentation coverage
- Integration into markdownToWiki.js pipeline
  - Applied after code block extraction, before text formatting
  - Preserves formatting syntax for text formatting converter
- Comprehensive test suite (34 tests)
  - 100% code coverage on tables.js
  - Security: XSS attempts preserved as text (handled by renderer)
  - Edge cases: empty cells, Unicode, emoji, special characters
  - Real-world examples: WordPress compatibility tables, bug tracking

Phase 7b: Tables Rendering (WikiFormatting → React)
- Core renderer: src/renderers/tables.js
  - Renders WikiFormatting tables as React <table> elements
  - Headers with '''Header''' → <thead><th>
  - Regular rows → <tbody><td>
  - Cell content parsed for inline formatting (bold, italic, links, code)
  - Pure React rendering (NO dangerouslySetInnerHTML)
  - React auto-escaping prevents XSS attacks
- Integration into wikiToReact.js
  - Table detection with isTableRow()
  - Multi-row parsing with parseTable()
  - Cell content through parseLinks() for security
- Styling in RenderedView.css
  - Trac-like table styling (borders, headers, alternating rows)
  - Dark mode support
  - Responsive design with horizontal scroll for wide tables
  - Formatting inside cells (code, links styled appropriately)
- Comprehensive test suite (29 tests)
  - 100% test coverage on tables.js renderer
  - Security: XSS attacks properly escaped (React auto-escaping)
  - Edge cases: empty cells, header-only, no-header tables
  - Real-world examples: WordPress compatibility, bug tracking

Testing & Documentation:
- TESTING_tables.md: Manual testing file with 40+ examples
  - Basic tables, formatting in cells, multiple tables
  - Security test cases: 15+ XSS attack vectors
  - WordPress examples: compatibility, components, functions
  - Verification checklists for all three columns

Integration Tests:
- 12 new integration tests in markdownToWiki.test.js
- Tables with headers, text formatting, links, inline code
- Tables with other elements (headers, code blocks, blockquotes)
- Complex documents with mixed content

Security Review: PASSED
- No dangerouslySetInnerHTML usage
- React auto-escaping active for all cell content
- Type validation present
- Secure data flow: Markdown → WikiFormatting (text) → React (escaped)
- Consistent with Phases 4, 5, 6 security patterns

Statistics:
- 662 tests passing (63 new table-specific tests)
- 100% coverage on converters and renderers
- 0 security vulnerabilities
- All previous tests still passing

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Comment thread src/converters/tables.js

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cover every possible Markdown table formatting? Do some research on the web to make sure we have all use cases covered

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if new table formats are added, make sure to update tests

Comment thread TESTING_tables.md
Comment on lines +16 to +22
### Simple 2x2 Table

| Header 1 | Header 2 |
|----------|----------|
| Cell 1 | Cell 2 |

Expected Column 2: `|| '''Header 1''' || '''Header 2''' ||` and `|| Cell 1 || Cell 2 ||`

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread TESTING_tables.md

Expected Column 2: `|| '''Header 1''' || '''Header 2''' ||` and `|| Cell 1 || Cell 2 ||`

### Single Column Table

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Comment thread TESTING_tables.md Outdated
Comment on lines +40 to +66
## Table Alignment

### Left-Aligned

| Left | Align |
|:-----|:------|
| L | Text |

### Center-Aligned

| Center | Align |
|:------:|:------:|
| C | Text |

### Right-Aligned

| Right | Align |
|------:|------:|
| R | Text |

### Mixed Alignment

| Left | Center | Right |
|:-----|:------:|------:|
| L | C | R |

**Note:** Alignment syntax (`:---`, `---:`, `:---:`) is preserved but Column 3 uses default left alignment (WikiFormatting limitation).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alignments do not appear to be working.

flexseth and others added 4 commits August 16, 2026 10:31
- Converter: Parse Markdown alignment syntax (:---, ---:, :---:)
- Converter: Apply WikiFormatting whitespace positioning
  - Left: text sticks to left separator with right padding
  - Right: text sticks to right separator with left padding
  - Center: equal padding on both sides
- Renderer: Detect alignment from whitespace patterns
- Renderer: Changed cell structure from strings to {content, align} objects
- Renderer: Apply CSS text-align to table cells
- Tests: Updated all renderer tests to match new cell structure
- Tests: Added alignment test cases to both converter and renderer
- Testing: Added alignment examples to TESTING_tables.md

All 63 table tests passing (34 converter + 29 renderer).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added four realistic, wide-column table examples:
- Product Pricing Table: Mixed alignment with longer content
- Statistics Dashboard: Number alignment with metrics
- Documentation Table: Technical content with functions/methods
- Comparison Table: Left vs right emphasis in feature comparison

These larger tables make the visual alignment differences more apparent
in Column 3 (Rendered Preview) compared to the previous single-letter
examples.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Comment thread TESTING_tables.md
Comment on lines +42 to +64
### Left-Aligned

| Column One | Column Two |
|:--------------------|:--------------------|
| Left aligned text | More left text |
| Short | Longer content here |
| WordPress | Development |

### Center-Aligned

| Column One | Column Two |
|:-------------------:|:-------------------:|
| Center aligned text | More centered text |
| Short | Longer content here |
| WordPress | Development |

### Right-Aligned

| Column One | Column Two |
|--------------------:|--------------------:|
| Right aligned text | More right text |
| Short | Longer content here |
| WordPress | Development |

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread TESTING_tables.md
Comment on lines +83 to +104
### Alignment Comparison Table (Test All At Once)

Copy this table to see all four alignment types side-by-side:

| No Align | Left Align | Center Align | Right Align |
|----------|:-----------|:------------:|------------:|
| Default | Left | Center | Right |
| Text | Sticks | Padded | Ends |
| Normal | Start | Both Sides | Right Side |

**What to verify in Column 2 (WikiFormatting):**
- Column 1 (No marker `---`): `|| Default ||` - single space both sides
- Column 2 (Left `:---`): `||Left ||` - text touches left `||`, spaces on right
- Column 3 (Center `:---:`): `|| Center ||` - equal spaces both sides
- Column 4 (Right `---:`): `|| Right||` - spaces on left, text touches right `||`

**What to verify in Column 3 (Rendered):**
- Column 1: Default left-aligned rendering
- Column 2: Text aligned to left edge of cell
- Column 3: Text centered in cell
- Column 4: Text aligned to right edge of cell

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant