Skip to content

Fix issue #432: restore natural table width and horizontal scrolling#440

Merged
schuyler merged 1 commit into
schuyler:mainfrom
samqbush:claude/fix-issue-432-table-visualization-1780326794
Jun 23, 2026
Merged

Fix issue #432: restore natural table width and horizontal scrolling#440
schuyler merged 1 commit into
schuyler:mainfrom
samqbush:claude/fix-issue-432-table-visualization-1780326794

Conversation

@samqbush

@samqbush samqbush commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Wide Markdown tables are squeezed to the visible pane width with no horizontal scrolling. Old MacDown v0.7.2 rendered wide tables at natural width and allowed horizontal scrolling via WebKit's NSScrollView.

Closes #432

Root Causes (both verified in main)

Cause 1 — GitHub-2020.css default theme body table rule

width: max-content was immediately cancelled by max-width: 100%, clamping the table to the pane width so overflow: auto had nothing to scroll.

Cause 2 — export.css (loads last, all themes) td, th rule

word-break: break-word forced mid-word cell breaks universally, collapsing column widths across every theme regardless of Cause 1.

Changes

MacDown/Resources/Styles/GitHub-2020.css

/* Before */
body table {
  display: block;
  width: 100%;
  width: max-content;
  max-width: 100%;      /* ← kills scrolling */
  overflow: auto;
  font-variant: tabular-nums;
}

/* After */
body table {
  display: block;
  width: max-content;
  min-width: 100%;      /* fill pane, allow growth */
  overflow-x: auto;
  font-variant: tabular-nums;
}

MacDown/Resources/Extensions/export.css

/* Before */
td, th {
    word-break: break-word;     /* ← collapses columns */
    overflow-wrap: break-word;
}

/* After */
td, th {
    overflow-wrap: break-word;  /* long URLs still wrap; cells size naturally */
}

MacDownTests/Fixtures/tables.md + tables.html

Added a 10-column wide-table regression fixture to guard against re-introducing either regression.

Testing

  • All 56 tests in MPMarkdownRenderingTests and MPHTMLExportTests pass (including the new wide-table fixture).

…rolling

Two CSS regressions caused wide tables to be squeezed to the pane
width with no horizontal scrolling.

Fix A — GitHub-2020.css (default theme):
The 'body table' rule combined 'width: max-content' with 'max-width: 100%',
causing max-width to cancel max-content so the table could never exceed
the pane width and overflow: auto had nothing to scroll.

Replace with:
  display: block;
  width: max-content;
  min-width: 100%;   (fill pane; allow growth beyond it)
  overflow-x: auto;

Fix B — export.css (all themes, loads last):
'td, th { word-break: break-word }' forced mid-word cell breaks
universally, collapsing column widths across every theme.

Drop word-break, keep overflow-wrap: break-word so cells size to
natural content width while truly unbreakable strings (e.g. long URLs)
still wrap rather than expanding the table infinitely.

Add a 10-column wide-table regression fixture to
MacDownTests/Fixtures/tables.md + tables.html to guard against
re-introducing either regression.

Related to schuyler#432
@schuyler schuyler merged commit c34f75f into schuyler:main Jun 23, 2026
6 checks passed
schuyler pushed a commit that referenced this pull request Jun 23, 2026
PR #440 restored natural table width and horizontal scrolling for the
default GitHub-2020 theme (via its own `body table` rule) and removed the
column-collapsing `word-break: break-word` from export.css for all themes.

The other ten themes, however, declare bare `table` rules with no overflow
handling, so a wide table there has no scroll container: it overflows the
pane and relies on document-level scrolling that may not be available.

Add a universal `table` scroll container to export.css (which loads last,
so it applies to every theme except where a higher-specificity `body table`
rule already wins, i.e. the default theme). Use the proven GitHub pattern --
`display: block; width: max-content; max-width: 100%; overflow-x: auto` --
so the scrollbar stays on the table itself.

Scope it to `@media screen` so PDF/print layout remains governed by
print.css; an overflow scroll container would otherwise clip wide tables on
paper rather than scrolling them.

Related to #432
schuyler pushed a commit that referenced this pull request Jun 23, 2026
PR #440 restored natural table width and horizontal scrolling for the
default GitHub-2020 theme (via its own `body table` rule) and removed the
column-collapsing `word-break: break-word` from export.css for all themes.

The other ten themes, however, declare bare `table` rules with no overflow
handling, so a wide table there has no scroll container: it overflows the
pane and relies on document-level scrolling that may not be available.

Add a universal `table` scroll container to export.css (which loads last,
so it applies to every theme except where a higher-specificity `body table`
rule already wins, i.e. the default theme). Use the proven GitHub pattern --
`display: block; width: max-content; max-width: 100%; overflow-x: auto` --
so the scrollbar stays on the table itself.

Scope it to `@media screen` so PDF/print layout remains governed by
print.css; an overflow scroll container would otherwise clip wide tables on
paper rather than scrolling them.

Related to #432
schuyler added a commit that referenced this pull request Jun 23, 2026
)

## Summary

Follow-up to #440. That PR restored natural table width and horizontal
scrolling for the **default GitHub-2020 theme** (via its own `body
table` rule) and removed the column-collapsing `word-break: break-word`
from `export.css` for all themes.

The other ten themes, however, declare bare `table { ... }` rules with
**no overflow handling**, so a wide table under those themes still has
no scroll container — it overflows the pane and relies on document-level
scrolling that may not be available. This PR closes that gap.

## Change

A single rule added to `MacDown/Resources/Extensions/export.css` (which
is appended last in the cascade):

```css
@media screen {
    table {
        display: block;
        width: max-content;
        max-width: 100%;
        overflow-x: auto;
    }
}
```

Design notes:

- **Cascade, not specificity.** The non-default themes use bare `table`
selectors of *equal* specificity; this rule wins because `export.css`
loads last (see `MPRenderer.m`). The default GitHub-2020 theme uses a
higher-specificity `body table` rule and is intentionally left
untouched, keeping #440's behavior.
- **`@media screen` is deliberate.** `export.css` is also present when
the preview is printed to PDF, where WebKit switches to print media. An
unscoped scroll container would *clip* wide tables on paper; the screen
scope confines this to the live preview and browser-viewed HTML and
leaves PDF layout to `print.css` (whose `overflow: visible` reset only
covers `pre`, not tables).
- **`max-width: 100%`** keeps the scrollbar attached to the table itself
rather than relying on document-level horizontal scrolling.

## Testing

Tables are rendered via CSS in the preview WebView, so the existing
fixture tests (which only cover the markdown→HTML step) do not exercise
this behavior. Verify manually on macOS:

1. Open a document containing a wide table (≥10 columns) — the `## Wide
Table` block in `MacDownTests/Fixtures/tables.md` works well.
2. **Default theme (GitHub-2020):** confirm the table keeps its natural
width and scrolls horizontally — i.e. no regression from #440.
3. **Each non-default theme** (Preferences → Rendering → Style): GitHub,
GitHub2, GitHub Tomorrow, Github2 (dark), Google Docs, Gmail, Clearness,
Clearness Dark, Solarized (Light), Solarized (Dark). For each, confirm
the wide table now scrolls horizontally instead of compressing columns.
This is the core thing the PR fixes.
4. **Narrow tables:** confirm small tables still render normally (they
shrink-wrap to content width under this rule, which is expected).
5. **PDF export (regression guard):** with a wide table, File → Export →
PDF under both a default and a non-default theme, and confirm the table
is **not** clipped on the page (the `@media screen` scope should keep
`print.css` in charge).
6. Long-URL cell content still wraps rather than expanding the table
indefinitely (preserved via `overflow-wrap` from #440).

Related to #432

---
_Generated by [Claude
Code](https://claude.ai/code/session_01T1WVepxgPRKafX2wQsz8Fv)_

Co-authored-by: Claude <[email protected]>
falcon-enoc added a commit to falcon-enoc/macdown3000 that referenced this pull request Jun 24, 2026
Regenerate tables.html golden so the "Wide Table" heading (added in
schuyler#440) carries the slug id emitted by the anchor-id logic, keeping the
exact-match rendering test green against current main.
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.

Incorrect table columns visualization compared to old Mac Down v0.7.2

2 participants