Conversation
prepareContent rewrote element names into markdown links even inside fenced and inline code blocks, corrupting code content. Skip fenced (```/~~~) and single-line inline code spans when linking, and skip linking entirely when content will be wrapped as a code block. Fences are also recognized behind a blockquote prefix (>), so a quoted fenced snippet is skipped the same way. A fence opened behind a blockquote prefix now closes as soon as a later line no longer carries that same prefix (shallower/different nesting, or a lazy line with none at all), matching CommonMark: the container ending closes the fence with it. Previously a mismatched or missing prefix left the fence open forever, silently dropping links from all following prose. Fixes Chainlit#3055 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
taekop
requested review from
asvishnyakov,
hayescode and
sandangel
as code owners
September 23, 2026 05:47
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…r code spans Blockquote fence tracking compared the literal `> ` prefix string, so a bare `>` line (no trailing space) inside a quoted fence closed it early and let later code lines get linked. Compare quote depth instead. The inline-code scanner treated any backtick preceded by a single `\` as escaped; CommonMark only escapes it behind an odd backslash run. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
prepareContentrewrites element names into[name](target)links on the raw message text, so names inside fenced code blocks and inline code were rewritten too, and so was content that gets wrapped as a code block vialanguage.It now walks the text line by line and only links names outside code: fenced blocks (
```or~~~at the start of a line, including behind>blockquote prefixes; an unclosed fence while streaming counts as code to the end) and inline backtick spans within a single line are left as is. Whenlanguagewraps the content as code, nothing is linked. Anything not clearly code, like a stray backtick, is linked exactly as before.I kept this as a text pass in
prepareContentto keep the change small. Doing it as a remark plugin inMarkdown.tsxwould also cover the limitations below, butrefElementswould have to move to render time, and names written likeSources:source_1get parsed byremark-directivebefore a plugin sees them, so it turned into a much larger change. Happy to go that way instead if you prefer.Known limitations (same as before): fences inside list items indented 4+ spaces, indented code blocks without a fence, and inline code spans whose backticks are on different lines still get names linked.
Tests:
cd frontend && pnpm test→ 47 passed, 15 of them new infrontend/tests/prepareContent.spec.ts.Fixes #3055
Summary by cubic
Fixes
prepareContentcorrupting element names in code blocks when linking them.Now, names inside fenced (
```or~~~) and single-line inline backtick code spans are left untouched, and linking is skipped entirely when content is wrapped as a code block vialanguage. Frames are recognized behind blockquotes, and blockquote depth is handled correctly, including a bare>or no-prefix line closing the fence per CommonMark. Inline code uses CommonMark backslash escaping rules, only treating backticks backslash pairs as escaped.Written for commit 43c6161. Summary will update on new commits.