Files
Project-Thoth/applications/chatgpt-capture/codex-work-orders/debugging/0003-table-defects.md
T

2.3 KiB

Fix ChatGPT DOM extractor table handling.

Observed defect: Tables in ChatGPT responses are being flattened into line-by-line text instead of Markdown tables.

Example bad output: Goal

Good Plant Choices

Attract deer

Hostas, daylilies, many ornamentals

Feed pollinators

Native flowering perennials, shrubs, trees

Expected output:

Goal Good Plant Choices
Attract deer Hostas, daylilies, many ornamentals
Feed pollinators Native flowering perennials, shrubs, trees
Prevent deer damage Deer-resistant species
Support overall biodiversity A mix of native plants with different bloom times

Requirements:

  1. Update src/chatgptExtractor.js.

  2. Add table-to-Markdown support:

    • Detect elements.
    • Extract rows from
    • .
    • Extract header cells from
    • , use that as the header.
    • If no
    • exists but the first row uses
      .
    • Extract data cells from
    • .
    • Preserve cell order.
    • Trim cell text.
    • Convert inline formatting inside cells using existing inline extractor.
    • Markdown table rules:

      • First row should become the header row.
      • If the table has
    • , use that row as the header.
    • If no header exists, use the first row as the header for MVP.
    • Add separator row using ---.
    • Escape pipe characters inside cells as \|.
    • Replace internal newlines in cells with <br> or a single space.
    • Example output format:

      Goal Good Plant Choices
      Attract deer Hostas, daylilies, many ornamentals
    • Ensure table extraction is treated as a block element:

      • Tables should be separated from surrounding paragraphs by blank lines.
      • Do not also extract duplicate flattened table text from child nodes.
    • Preserve other existing behavior:

      • Paragraphs remain paragraphs.
      • Lists remain Markdown lists.
      • Code blocks remain fenced code.
      • Bold/italic/inline code remain inline.
      • Message order and role detection unchanged.
    • Suggested helper: function tableToMarkdown(tableNode, context) { // return markdown table string }

      Acceptance criteria:

      • ChatGPT tables export as valid Markdown tables.
      • Headers and rows are preserved.
      • Pipe characters inside cells are escaped.
      • Tables are not duplicated as flattened text.
      • Surrounding prose remains intact.
      • No LLM calls.
      • No Project Thoth application dependency.