Skip to content

Shell fences in chat code blocks are lexed as JavaScript #1751

Closed

Description

@smsunarto

What happens

Found this while theming bb. A shell fence in a thread message comes out lexed as JavaScript: # install the plugin is a sign and three identifiers, and ./plugins/monokai is a string. Python, Rust, Go, C, Java and CSS fences are fine, which is what threw me at first.

Why

The fence language is read and mapped to a preset:

// apps/app/src/components/ui/markdown-code-highlight.ts
const preset = language === null ? undefined : PRESET_BY_LANGUAGE[language];
return highlight(code, preset);

There's no shell key in the map, and no shell preset in sugar-high v1 to point one at. v1 ships eight: c, css, diff, go, java, json, python, rust. Same for yaml, sql, html, markdown, toml and dockerfile.

diff and json are the two of the eight the map doesn't use. If that's deliberate, ignore me.

Proposal

Streamdown for chat markdown. Its Shiki plugin takes the language:

// [email protected], dist/index.d.ts
interface HighlightOptions {
  code: string
  language: BundledLanguage
  themes: [ThemeInput, ThemeInput]
}

highlight: (options: HighlightOptions, callback?: (result: HighlightResult) => void) => HighlightResult | null

It colors through --shiki-dark and --sdm-c, so chat fences would land on the same theme as diffs and file previews instead of the separate --sh-* set.

I have a PoC of the swap in #1317, opened for render cost rather than for this. Not asking for it here, it's evidence the swap is tractable.

Smaller version if the migration isn't on the table: sugar-high v2 takes a lang string and ships 25 languages, shell among them.

-import { highlight } from 'sugar-high'
-import { c, css, go, java, python, rust } from 'sugar-high/presets'
+import { highlight } from 'sugar-high'
+import { lang } from 'sugar-high/lang'

-highlight(code, PRESET_BY_LANGUAGE[language])
+highlight(code, { lang: lang(language) })

lang() returns undefined for h, hpp and less, which the map covers today. Either way v2 still colors through --sh-*, so chat and diffs stay on separate themes.

Refs

Activity

  1. added theissue type on Aug 18, 2026
  2. added
    ui
    on Aug 18, 2026
  3. SawyerHood commented on Aug 18, 2026

    @SawyerHood
    Collaborator

    Reproduction & root-cause report: https://get-bb.github.io/reports/issues/1751.html

    • Verdict: REPRODUCED · root-cause confidence: high
    • Root cause (short): apps/app/src/components/ui/markdown-code-highlight.ts maps only rust/python/go/c/java/css fence languages to sugar-high v1 presets; sh/bash/shell/zsh/console (and yaml, toml, sql, diff, ...) get preset=undefined and fall through to sugar-high's JavaScript lexer, so # is a sign, words are identifiers, and /plugins/monokai is a regex-literal string.
    • Proposed fix: Preferred: bump apps/app sugar-high to ^2.0.1 and in markdown-code-highlight.ts replace the preset map with import { lang } from "sugar-high/lang" -> highlight(code, { lang: lang(language) ?? EXTRA_ALIASES[language] }), with EXTRA_ALIASES covering h/hpp->c(pp), less->css, console->shell (verified: lang() maps sh/bash/zsh/shell->shell and 25 langs incl. yaml/toml/sql/diff/json; HTML still uses sh__token--* / --sh-* so the CSS is untouched; only this file imports sugar-high). Alternative minimal v1 patch: add a local shell preset (python-style # comment handlers + shell keywords) mapped fr…
    • Caveats: No linked PR to review (PR perf(app): replace react-markdown with Streamdown (PoC) #1317 is a Streamdown PoC referenced only as evidence). Minor issue inaccuracy: sugar-high 1.2.1 ships seven presets (no json), not eight. Screenshots are light theme only. Worktree was moved to base 16ceb3a (HEAD was origin/main a108fa7, which does not touch the relevant files, so not fixed upstream). Two untracked repro test files remain in the worktree under apps/…

    The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at 16ceb3a54, and repro artifacts. It was independently re-run by a second agent (see its Verification section).

    AGENT GENERATED: by Claude Opus 5

  4. added
    confirmed-repro
    on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproui

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions