Skip to content

fix(tui): render ~~~ fences as code blocks - #7156

Merged
Hmbown merged 1 commit into
codewhale-hq:mainfrom
Lstarsky0:fix/tilde-code-fences
Oct 31, 2026
Merged

Hmbown merged 1 commit into
codewhale-hq:mainfrom
Lstarsky0:fix/tilde-code-fences

Conversation

@Lstarsky0

Copy link
Copy Markdown
Contributor

What and why

The markdown renderer only knows backtick fences, so a code block opened with ~~~ renders as prose, although the rest of the codebase already treats ~~~ as a fence (memory import, the agent roster, the plan handoff title). ~~~ is a common way to wrap text that has backtick fences of its own, such as a README section. In prose, a # comment line becomes a heading with a rule under it, indentation is dropped, and *all* turns italic. At 80 columns, before:

● Here is the script:
▏
▏ ~~~python
▏ Count the lines in each file
▏ ────────────────────────────────────────
▏ import sys
▏
▏ for path in sys.argv[1:]:
▏ with open(path) as f:
▏ print(path, sum(1 for _ in f))  # all lines
▏ ~~~
▏
▏ And the README section, which has a fence of its own:
▏
▏ ~~~markdown
▏ Usage
▏
    python count.py *.txt
▏ ~~~
▏
▏ Done.

After:

● Here is the script:
▏
    # Count the lines in each file
    import sys

    for path in sys.argv[1:]:
        with open(path) as f:
            print(path, sum(1 for _ in f))  # *all* lines
▏
▏ And the README section, which has a fence of its own:
▏
    ## Usage

    ```bash
    python count.py *.txt
    ```
▏
▏ Done.

The parser's fence carry now records the fence character along with its length. A fence closes only on the same character and at least the opener's length, so a backtick fence inside a ~~~ block is code, and the other way round. Backtick fences parse as before. streaming_preview_tail_source in the thinking preview mirrors the parser's fence rule to pick a cut that isn't inside a code block (a review note on #6249 pointed out the two would drift if the parser learned tilde fences), so it gets the same change; without it, a cut could land inside a ~~~ block and the preview would render the rest of that block as prose.

This touches the same lines as #7146 (the parser's carry and push_parsed_line's signature). If that one lands first, I'll merge main in and resolve it here.

Issue

No-Issue: code blocks fenced with ~~~ render as prose in the transcript; I searched and found no issue for it

How I tested it

  • Ran a debug build of this change and one of main at 36f058c in a pseudo-terminal at 80x50 with an empty HOME and a local mock OpenAI-compatible server replying with the message above; the rows above come from those runs. A second reply checked the edges: ~~~bash and backtick bash blocks holding echo "$HOME and $USER" both render as code with the $ left alone, a four-backtick block keeps a ~~~ line inside it as code, a ~~~~ block is not closed by ~~~, and ~~struck~~ text still renders struck through. On main the ~~~bash line shows as text and the ~~~~ block's - inside lines render as list items.
  • cargo nextest run -p codewhale-tui -p codewhale-tui-kit --lib: 13623 of 13625 passed, with the 266 tests whose names match markdown, fence or thinking among them. The 2 failures (status_report_localizes_the_complete_japanese_surface, test_update_model_compaction_budget) also fail on main at 36f058c without this change.
  • cargo fmt --all -- --check, cargo clippy -p codewhale-tui -p codewhale-tui-kit with CI's flags (also on 1.99), cargo check -p codewhale-tui -p codewhale-tui-kit --all-targets, cargo +1.89.0 check -p codewhale-tui -p codewhale-tui-kit and cargo doc -p codewhale-tui-kit --no-deps with -D warnings: clean.

Checklist

  • One focused change, on 36f058c; it merges cleanly into current main
  • cargo fmt --all passes, and tests cover new or changed behavior — cargo fmt passes; no new test, per AGENTS.md, so the runs above stand in for one
  • If this adds or changes a user-facing feature, I updated its docs and its row in docs/features.toml (cargo test -p codewhale-tui --test feature_registry checks it) — n/a

The markdown renderer only knew backtick fences, so a block opened with
~~~ rendered as prose: a `# comment` line became a heading with a rule
under it, indentation was dropped, and `*x*` turned italic. The rest of
the codebase already treats ~~~ as a fence (memory import, the agent
roster, the plan handoff title).

The fence carry now records the character along with the length. A
fence closes only on the same character and at least the opener's
length, so a ``` line inside a ~~~ block is code, and the other way
round. Backtick fences parse as before. The streaming thinking preview
mirrors the parser's fence rule to find a safe cut, so it follows.

Signed-off-by: Lstarsky0 <59827030+Lstarsky0@users.noreply.github.com>
@Lstarsky0
Lstarsky0 requested a review from Hmbown as a code owner October 30, 2026 16:01

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added the contribution-gate Author not yet in .github/APPROVED_CONTRIBUTORS; a maintainer grants access with /lgtm label Oct 30, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-30T16:03:39.723787Z
We couldn’t complete this review. Comment @codex review to try again.
d0d4f45 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.

@Hmbown
Hmbown merged commit 2fb9267 into codewhale-hq:main Oct 31, 2026
28 checks passed
Hmbown pushed a commit that referenced this pull request Oct 31, 2026
…urfaces

Changelog lines for #7147, #7146, #7156, #7157, #7158, #7152 and #7150, and
credit for the contributors across CHANGELOG `### Contributors`,
docs/CONTRIBUTORS.md and UNRELEASED_CONTRIBUTORS (adds @luochen211, whose #7150
and #7149 landed). #7149 is a dead-code chore and has no changelog line.

Verified: `python3 scripts/check-contributor-credit.py` reports every contributor
in the window credited on all three surfaces; `scripts/preflight.sh --check`
passes; `sh scripts/sync-changelog.sh` regenerated crates/tui/CHANGELOG.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution-gate Author not yet in .github/APPROVED_CONTRIBUTORS; a maintainer grants access with /lgtm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants