Repository navigation
Keep paragraph spacing, headings, lists and tables in IM text - #18
neotechnet wants to merge 1 commit into
Conversation
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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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*$/ |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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 👍 / 👎.
| return splitRuns(block.lines) | ||
| .map(run => (run.kind === 'table' | ||
| ? `<pre>${escapeHtml(padRows(tableRows(run.lines), inlinePlain).join('\n'))}</pre>` | ||
| : renderHtmlLines(run.lines))) |
There was a problem hiding this comment.
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 👍 / 👎.
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, notdev. This is the branch that produces what the running profile loads. The same blob76e06ff1is the file onorigin/main,origin/devand this stack, so the change applies cleanly to any of them, and the upstream twin belongs ondevwhen a release is cut.What changed
ds-bot/src/host/im/format.jsBLOCK_JOIN), so paragraph breaks survive. This is the defect:flush()threw every blank line away and the renderers rejoined with a single\n.#markers are gone.<pre>grid, padded to the widest cell, with the separator row dropped.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
isHeadingand never used it, which oxlint rejects asno-unused-vars, failingnpm run lint. I removed that one line. Everything else is byte-identical to the patch: the file hashes3E0F20B699AA22BC39FB4CC8413AA3F3A2B0FE6B93E8F70FE0594F75E218DFBChere against5E46E33DF075E1A10A5E49D9FCA61CAA66A1C04B2153F133FA03884267FD4DEFpatched, and the difference is exactly that line.The existing test was asserting the defect
Markdown becomes Telegram HTMLexpectedbefore\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.jsenv sanitization)node scripts/build-client.mjs --check(rc 0)npm run lint(0 errors, 76 pre-existing warnings)im-format.test.js8 of 8, and the three IM test files 42 of 42Changelog
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
src/client/not changed, soclient.jsis untouchedCo-authored-by