Skip to content

Fix table markup alignment#224

Merged
ericdallo merged 3 commits intoeditor-code-assistant:masterfrom
avehtari:fix-table-markup-alignment
Apr 17, 2026
Merged

Fix table markup alignment#224
ericdallo merged 3 commits intoeditor-code-assistant:masterfrom
avehtari:fix-table-markup-alignment

Conversation

@avehtari
Copy link
Copy Markdown
Contributor

Fix table column alignment with bold/italic markup

When markdown-hide-markup is enabled, bold and italic delimiters (**, *) are
hidden from display but markdown-table-align pads cells based on raw character
width including those delimiters. This causes columns with markup to appear narrower
than intended:

  • Bold cell (**text**): 4 chars too narrow
  • Italic cell (*text*): 2 chars too narrow

Example

| **Column A** | **Column B** |        | Column A | Column B |
|--------------|--------------|   →    |----------|----------|
| **25**       | 30           |        | 25   | 30           |
| 40           | *50*         |        | 40       | 50       |
  raw text (aligned)                     displayed (misaligned)

Fix

After markdown-table-align pads each table, a new function
eca-table--compensate-hidden-markup scans each cell for */** delimiter
pairs via regex and adds an overlay with an after-string of compensating
spaces:

| Column A     | Column B     |
|--------------|--------------|
| 25    ····   | 30           |   (···· = 4-space overlay after-string)
| 40           | 50  ··       |   (·· = 2-space overlay after-string)

Key details:

  • Regex-based counting — does not depend on font-lock timing
  • Overlay-only — no buffer text modification; overlays use eca-table-markup-pad
    property (not eca-table-overlay) so eca-table-remove-overlays in the beautify
    step does not wipe them
  • Idempotent — removes previous compensation overlays before reapplying
  • 1-char overlay — avoids zero-width overlays which Emacs deletes immediately
    when evaporate is set
  • eca-table--max-line-width updated to subtract hidden markup for accurate
    wide-table detection

Files changed

  • eca-table.el — added eca-table--count-markup-chars,
    eca-table--compensate-hidden-markup; updated eca-table-align and
    eca-table--max-line-width
  • test/eca-table-markup-test.el — interactive visual test (M-x eca-table-markup-test)

Notes

Code and PR description with help from Claude. In addition to the test code included, I have tested with many other tables.
and programmatic checks (M-x eca-table-markup-test-run-checks)

Copy link
Copy Markdown
Member

@ericdallo ericdallo left a comment

Choose a reason for hiding this comment

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

Thank you!

@ericdallo ericdallo merged commit 7b8085c into editor-code-assistant:master Apr 17, 2026
15 checks passed
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