Skip to content

Help editor integrations rewrite Markdown tables without drifting or hanging - #2

Open
dnouri wants to merge 1 commit into
mainfrom
helper-table-inspection
Open

Help editor integrations rewrite Markdown tables without drifting or hanging#2
dnouri wants to merge 1 commit into
mainfrom
helper-table-inspection

Conversation

@dnouri

@dnouri dnouri commented Mar 16, 2026

Copy link
Copy Markdown
Owner

Markdown table wrapping is most useful when editor commands can apply it
repeatedly to source buffers. Until now that path was awkward and easy
to get wrong. Callers had to rediscover table boundaries themselves,
guess whether they were looking at source or already-wrapped output,
preserve indentation and trailing newlines by hand, and hope they were
not sitting at EOF or inside a fenced block. Even when helper code
found the right block, wrapped-looking pipe tables with multi-line
headers or continuation-style values could still lose structure on
rewrite. The README mirrored that brittleness by spelling out the same
low-level replacement dance in each recipe.

Teach the library the editor-facing operations it was missing. Give it
a way to find pipe-table blocks in buffers while skipping fenced code
blocks, normalize same-width wrapped output back to source form, and
format extracted table blocks so repeated rewrites preserve indentation,
newline shape, and recoverable wrapped structure. Merge visual header
rows before the separator instead of discarding all but the last one, so
helper-driven rewrites keep wrapped-like header content intact. That
gives wrapping at point, buffer-wide cleanup, and save-hook workflows
one safe path instead of several fragile ones.

Rewrite the integration documentation around that safer path and back it
with coverage for EOF tables, region discovery, idempotent same-width
rewrites, indentation-preserving reinsertions, README-driven editing
flows, and pseudo-table blocks with multi-line headers or continuation
rows. The result is a table wrapper that behaves predictably in real
editing sessions instead of asking every caller to reconstruct its edge
cases from scratch.

@dnouri
dnouri force-pushed the helper-table-inspection branch from 59759cd to 4d7d7cb Compare March 16, 2026 09:40
…hanging

Markdown table wrapping is most useful when editor commands can apply it
repeatedly to source buffers.  Until now that path was awkward and easy
to get wrong.  Callers had to rediscover table boundaries themselves,
guess whether they were looking at source or already-wrapped output,
preserve indentation and trailing newlines by hand, and hope they were
not sitting at EOF or inside a fenced block.  Even when helper code
found the right block, wrapped-looking pipe tables with multi-line
headers or continuation-style values could still lose structure on
rewrite.  The README mirrored that brittleness by spelling out the same
low-level replacement dance in each recipe.

Teach the library the editor-facing operations it was missing.  Give it
a way to find pipe-table blocks in buffers while skipping fenced code
blocks, normalize same-width wrapped output back to source form, and
format extracted table blocks so repeated rewrites preserve indentation,
newline shape, and recoverable wrapped structure.  Merge visual header
rows before the separator instead of discarding all but the last one, so
helper-driven rewrites keep wrapped-like header content intact.  That
gives wrapping at point, buffer-wide cleanup, and save-hook workflows
one safe path instead of several fragile ones.

Rewrite the integration documentation around that safer path and back it
with coverage for EOF tables, region discovery, idempotent same-width
rewrites, indentation-preserving reinsertions, README-driven editing
flows, and pseudo-table blocks with multi-line headers or continuation
rows.  The result is a table wrapper that behaves predictably in real
editing sessions instead of asking every caller to reconstruct its edge
cases from scratch.
@SayreBlades

Copy link
Copy Markdown
Contributor

Nice — this is exactly the editor-facing API a display-overlay library wants. FWIW I'm working on a read-only pretty table renderer (display overlays over canonical source, toggled like org-latex-preview / inline images — no buffer mutation). It's complementary to this PR (which is about safely rewriting source; mine never rewrites, always renders from canonical). Once this merges I'd like to consume markdown-table-wrap-table-bounds / markdown-table-wrap-table-regions for detection and drop my vendored copies. No rush — just signaling demand.

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.

2 participants