[Gemini UI Bug] Nested Markdown code blocks break outer code fences early

When asking the Gemini model to provide the raw Markdown code for a full file (such as a README.md) that natively contains its own code blocks (like ```text or ```bash for setup instructions), the system wraps the overall response block in triple backticks as well.

Because it uses the exact same triple-backtick delimiter for both the outer wrapper and the inner file code blocks, the first inner closure sequence prematurely kills the main markdown wrapper block. This fragments the code block in the chat interface and ruins the one-click “Copy Code” function.

Actual Behavior:
The response breaks out of the code block layout as soon as the first internal markdown block ends, leaving the user with multiple broken UI chunks instead of a single, continuous markdown file template.

Expected Behavior:
When a markdown output requires nested code blocks, the outer container should automatically scale up to four backticks (````markdown … ````) or handle escaping sequences intelligently so the output remains intact within a single container.

This issue frequently disrupts development workflows when requesting complete documentation templates, multi-directory file trees, or onboarding files. It requires users to manually copy multiple distinct pieces of text and reconstruct the formatting boundaries themselves.

Suggested Solution / Fix:
The system should automatically default to four backticks (````) for the outer markdown code fence whenever nested triple-backtick blocks are detected in the generated content.

Note: Manually instructing Gemini in the prompt to “wrap the whole file in 4 backticks” actually works perfectly and prevents the layout from breaking. However, the model should handle this scaling dynamically by default without requiring explicit user instructions.

any fixes or workarounds for this found? this gets in my way every day:((.

Adding a case with a worse consequence than broken display: silent data loss through the code-block download (Gemini web app, 1 Oct 2026).

What happened

  • Gemini returned a long Markdown document wrapped in a single ```markdown code block. The document itself contained a ```text block (an ASCII diagram), followed by more sections.
  • As described above, the inner closing fence ended the outer block. That block’s download button then saved only the part before it: the file ended exactly on the diagram’s last line, without the closing fence and without any of the following sections. Nothing showed that the file was incomplete.
  • Trusting the download, I deleted the chat, and the rest of the document was lost.

Minimal reproduction (CommonMark rules, tested with markdown-it). Document placed inside a ```markdown wrapper:

# Sample Design Document

## 1. Overview

```text
+-----------+
|  Box A    |
+-----------+
```

## 2. Details
This section is missing from the downloaded file.

Result: with a 3-backtick outer fence the block keeps 10 of 19 lines and ends at +-----------+. With a 4-backtick outer fence (````) it keeps all 19 lines.

Update, 2 Oct 2026: three fresh sessions with the same model, parameters and prompt (“create a file for me to download”) delivered the document through the newer artifact view instead (two with the document uploaded, one with it pasted as text). All three downloads were complete, so the inline path could not be reproduced. It may have changed silently; I found no release note about it. Not tested: a long multi-turn chat like the original one.

Suggested fix: wrap documents that contain ``` fences in a longer outer fence (````), and have the download export the whole document, or at least warn when a block appears to end at a nested fence.

Minimal reproduction and evidence: Gemini web app: nested code fences truncate code-block downloads — minimal reproduction (MasteryFlow-Works) · GitHub

— MasteryFlow-Works · MasteryFlow-Works (Vadim Hesse) · GitHub