Skip to content

Keep paragraph spacing, headings, lists and tables in IM text - #18

Open
neotechnet wants to merge 1 commit into
stack/installed-0.3.2from
fix/telegram-format-spacing
Open

neotechnet wants to merge 1 commit into
stack/installed-0.3.2from
fix/telegram-format-spacing

Conversation

@neotechnet

Copy link
Copy Markdown
Owner

Issue

No repo issue. Defect LE-20261110-042: a Bot message relayed to Telegram arrived as one blob with no paragraph spacing, and ##, - and | arrived literally.

Base is stack/installed-0.3.2, not dev. This is the branch that produces what the running profile loads. The same blob 76e06ff1 is the file on origin/main, origin/dev and this stack, so the change applies cleanly to any of them, and the upstream twin belongs on dev when a release is cut.

What changed

ds-bot/src/host/im/format.js

  • Blocks are rejoined with a blank line (BLOCK_JOIN), so paragraph breaks survive. This is the defect: flush() threw every blank line away and the renderers rejoined with a single \n.
  • A heading becomes bold; the # markers are gone.
  • Consecutive list items are separated by a blank line.
  • A Markdown table becomes an aligned <pre> grid, padded to the widest cell, with the separator row dropped.
  • An underlined rule becomes a short dashed line rather than literal markers.
  • The four exports keep their names and their order.

ds-bot/test/im-format.test.js: four tests for the four rules, plus the existing fenced-code test corrected.

One change from the patch that was applied live

The live patch declared isHeading and never used it, which oxlint rejects as no-unused-vars, failing npm run lint. I removed that one line. Everything else is byte-identical to the patch: the file hashes 3E0F20B699AA22BC39FB4CC8413AA3F3A2B0FE6B93E8F70FE0594F75E218DFBC here against 5E46E33DF075E1A10A5E49D9FCA61CAA66A1C04B2153F133FA03884267FD4DEF patched, and the difference is exactly that line.

The existing test was asserting the defect

Markdown becomes Telegram HTML expected before\n<pre>...</pre>\nafter, a single newline between blocks, which is the blob behaviour being fixed. Its expectation now has the blank line. Worth knowing, because that assertion is why the defect could survive a green suite.

How I checked it

  • npm test: 2 failures, both pre-existing and unrelated (connectors-gateway.test.js, local-agents.test.js env sanitization)
  • node scripts/build-client.mjs --check (rc 0)
  • npm run lint (0 errors, 76 pre-existing warnings)
  • im-format.test.js 8 of 8, and the three IM test files 42 of 42
  • Smoke test: not run. Install and restart are Steve's step
  • Screenshot: no GUI change, the rendered text is asserted in the tests

Changelog

Telegram messages keep their paragraph spacing, show headings in bold, double space list items, and draw a Markdown table as an aligned monospace grid.

Checklist

  • One issue, one subject
  • src/client/ not changed, so client.js is untouched
  • No keys, tokens or personal data
  • No AI tool as author or Co-authored-by

A Bot message reached Telegram as one blob with no spacing. Blocks were rejoined with a single newline, so every blank line was thrown away, and headings, list markers and table pipes had no rule at all, so they arrived literally.

Blocks now rejoin with a blank line, a heading becomes bold, list items are double spaced, and a Markdown table becomes an aligned pre grid with its separator row dropped. The four exports keep their names and order.

The existing fenced-code test asserted the single-newline join, which is the behaviour being fixed, so its expectation moves to the blank line.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T01:11:30.262282Z c180c45 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c180c45651

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

.replace(/~~([^~]+)~~/g, '$1')
}

const HEADING_RE = /^\s{0,3}#{1,6}\s+(.*?)\s*#*\s*$/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve trailing hashes that belong to heading text

For a heading such as ## C#, the new regex consumes the final # as an optional closing marker, so both renderers change the content to C (toTelegramHtml('## C#') returns <b>C</b>). Closing heading markers should require preceding whitespace; otherwise legitimate names and other text ending in hashes are silently altered.

Useful? React with 👍 / 👎.

// A table row as plain cell strings. The leading and trailing pipe are framing, not cells.
function tableCells(line) {
const trimmed = line.trim().replace(/^\|/, '').replace(/\|$/, '')
return trimmed.split('|').map(cell => cell.trim())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep escaped pipes inside their table cells

When a Markdown table contains an escaped pipe, splitting on every | creates an extra column and removes the literal pipe from the content. For example, the row | a \| b | yes | under a two-column header renders as three cells containing a \, b, and yes, placing the result under the wrong column. Parse escaped delimiters before splitting and restore the literal pipe in the rendered cell.

Useful? React with 👍 / 👎.

Comment on lines +170 to +173
return splitRuns(block.lines)
.map(run => (run.kind === 'table'
? `<pre>${escapeHtml(padRows(tableRows(run.lines), inlinePlain).join('\n'))}</pre>`
: renderHtmlLines(run.lines)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the new formatting when splitting oversized blocks

For a table whose rendered block exceeds Telegram's 4096-character limit, chunkTelegram delegates to the unchanged forceCut, which processes the original lines using only inlineHtml and inlinePlain. Consequently, long tables are sent with literal pipes and separator rows instead of the aligned <pre> grid; long list blocks likewise lose the new spacing. The Telegram adapter's send path uses chunkTelegram, so this affects actual outbound messages even though the new tests exercise only the unchunked renderers. Make the oversized-block path retain the new block rendering while splitting.

Useful? React with 👍 / 👎.

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.

1 participant