From bba2178496ec7bd2d26f039a8c16e15a6ad9c106 Mon Sep 17 00:00:00 2001 From: Phil Date: Thu, 12 Nov 2026 13:24:37 -0700 Subject: [PATCH] fix: tables fill the column as a card, matching common Markdown viewers (v2.18.2) Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 +++++--- starpunk/models.py | 4 +++- static/css/style.css | 14 ++++++++------ tests/test_markdown_ext.py | 9 +++++++++ 4 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 tests/test_markdown_ext.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ae41d6..368f7da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Tables in notes and articles: words in cells were split mid-word (a narrow first column read "Colo/r", "Blac/k") and cells had no padding or left - alignment. Tables now keep words whole and render as a framed card: rounded - border, shaded header row, sans-serif text, bold first column. They size to - their content and scroll sideways on narrow screens. + alignment. Tables now keep words whole and render as a card that fills the + column: raised background, rounded border, shaded header row, roomy cells, + sans-serif text at reading size, bold first column. Rendered tables are + wrapped in `
`, which scrolls sideways on narrow + screens. ### Changed - Public pages are wider: 48rem instead of 40rem (about 85 characters per diff --git a/starpunk/models.py b/starpunk/models.py index 7e30374..20df00d 100644 --- a/starpunk/models.py +++ b/starpunk/models.py @@ -62,7 +62,9 @@ ALLOWED_ATTRIBUTES = { def render_markdown(text: str) -> str: """Note Markdown (or HTML) to sanitized HTML""" html = markdown.markdown(text, extensions=MARKDOWN_EXTENSIONS) - return nh3.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES) + html = nh3.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES) + # A wrapper lets a table fill the column yet scroll sideways when too wide (v2.18.2) + return re.sub(r"", "
") # Likes, reposts and bookmarks (v2.5.0, v2.9.0) diff --git a/static/css/style.css b/static/css/style.css index 0dc3097..bec72d1 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -91,12 +91,14 @@ main { flex: 1; margin-bottom: var(--spacing-xl); } .e-content blockquote { margin: 0 0 var(--spacing-md); padding-left: var(--spacing-md); border-left: 3px solid var(--color-border); color: var(--color-text-light); } .e-content ul, .e-content ol { margin: 0 0 var(--spacing-md) 1.25rem; } .e-content img { max-width: 100%; height: auto; } -/* Tables (v2.18.2): shrink to their content, scroll sideways when wider than - the column, and never split words (the overflow-wrap: anywhere above is for - long URLs in prose; in a cell it squeezed columns to a few letters). */ -.e-content table { display: block; width: max-content; max-width: 100%; overflow-x: auto; border-collapse: separate; border-spacing: 0; border: 1px solid var(--color-border); border-radius: var(--border-radius); margin: 0 0 var(--spacing-md); font-family: var(--font-body); font-size: 1rem; line-height: 1.55; } -.e-content th, .e-content td { padding: 0.75rem 1rem; text-align: left; vertical-align: top; overflow-wrap: normal; } -.e-content th { font-weight: 600; white-space: nowrap; background: var(--color-bg-alt); } +/* Tables (v2.18.2): a card that fills the column, in the page's sans font at + the reading size; scrolls sideways when wider than the column. Words in + cells are never split (overflow-wrap: anywhere above is for long URLs in + prose; in a cell it squeezed columns to a few letters). */ +.e-content .table-wrap { overflow-x: auto; margin: 0 0 var(--spacing-md); background: var(--color-bg-alt); border: 1px solid var(--color-border); border-radius: var(--border-radius); } +.e-content table { width: 100%; border-collapse: collapse; font-family: var(--font-body); font-size: 1.0625rem; line-height: 1.6; } +.e-content th, .e-content td { padding: 0.9rem 1.25rem; text-align: left; vertical-align: top; overflow-wrap: normal; } +.e-content th { font-weight: 600; white-space: nowrap; background: color-mix(in srgb, var(--color-text) 6%, var(--color-bg-alt)); } .e-content td:first-child { font-weight: 600; } .e-content h1, .e-content h2, .e-content h3 { font-family: var(--font-body); } .reaction { margin-bottom: var(--spacing-sm); font-size: 0.9375rem; color: var(--color-text-light); overflow-wrap: anywhere; } diff --git a/tests/test_markdown_ext.py b/tests/test_markdown_ext.py new file mode 100644 index 0000000..6838b84 --- /dev/null +++ b/tests/test_markdown_ext.py @@ -0,0 +1,9 @@ + + +def test_tables_get_a_scroll_wrapper(): + """v2.18.2: tables are wrapped so they can fill the column and scroll sideways""" + from starpunk.models import render_markdown + + html = render_markdown("| Color | Why |\n|---|---|\n| Black | Removal |\n\nAfter") + assert html.startswith('
') and "
" in html + assert "

After

" in html