Incorrect Rendering of Nested Code Blocks in Markdown #1934

Closed
opened 2025-11-11 14:56:47 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @frettig-radiox on GitHub (Aug 29, 2024).

Bug Report

When including a nested code block in Markdown, the rendered output did not display correctly in the UI. If the nested code block is not indented by the llm, the rendering of the code block fails.

Environment

  • Open WebUI Version: v0.3.16

Confirmation:

Expected Behavior:

The nested code block should be rendered correctly even if not indented.

Actual Behavior:

The nested code block gets displayed without proper formatting, which causes confusion in how the nested code appears on-screen.

Reproduction Details

Steps to Reproduce:

  1. Create a Markdown response with a code block containing another code block inside of it. (e.g. prompt "create markdown code with a nested python code block")
  2. Do not indent the nested code block initially.
  3. Check the Markdown code block in the chat
  4. Observe that the nested code block does not render correctly.

Logs and Screenshots

Screenshots:

Before indenting the nested code block:

screenshot_before

After indenting the nested code block:
screenshot_after

Reference Markdown Example:
Here's an example of the Markdown that caused the issue if it appears in the llm response:

```markdown
# Example of a nested Python code block

Here's a simple example of a Python function:

```python
    def greet(name):
        return f"Hello, {name}!"

    # Usage example
    print(greet("World"))
```

The above code defines a function that greets the user by name.
```

if the python block is indented, the code

block is rendered correctly:

```markdown
# Example of a nested Python code block

Here's a simple example of a Python function:

    ```python
    def greet(name):
        return f"Hello, {name}!"

    # Usage example
    print(greet("World"))
    ```

The above code defines a function that greets the user by name.
```
Originally created by @frettig-radiox on GitHub (Aug 29, 2024). # Bug Report When including a nested code block in Markdown, the rendered output did not display correctly in the UI. If the nested code block is not indented by the llm, the rendering of the code block fails. ## Environment - **Open WebUI Version:** v0.3.16 **Confirmation:** ## Expected Behavior: The nested code block should be rendered correctly even if not indented. ## Actual Behavior: The nested code block gets displayed without proper formatting, which causes confusion in how the nested code appears on-screen. ## Reproduction Details **Steps to Reproduce:** 1. Create a Markdown response with a code block containing another code block inside of it. (e.g. prompt "create markdown code with a nested python code block") 3. Do **not** indent the nested code block initially. 4. Check the Markdown code block in the chat 5. Observe that the nested code block does not render correctly. ## Logs and Screenshots **Screenshots:** *Before indenting the nested code block:* <img width="526" alt="screenshot_before" src="https://github.com/user-attachments/assets/3a89eca4-3213-4e9e-8fb2-c5ea53ee9c71"> *After indenting the nested code block:* <img width="531" alt="screenshot_after" src="https://github.com/user-attachments/assets/1f8cb968-d1cb-474a-a2d7-d7213d745562"> **Reference Markdown Example:** Here's an example of the Markdown that caused the issue if it appears in the llm response: ~~~ ```markdown # Example of a nested Python code block Here's a simple example of a Python function: ```python def greet(name): return f"Hello, {name}!" # Usage example print(greet("World")) ``` The above code defines a function that greets the user by name. ``` ~~~ if the python block is indented, the code block is rendered correctly: ~~~ ```markdown # Example of a nested Python code block Here's a simple example of a Python function: ```python def greet(name): return f"Hello, {name}!" # Usage example print(greet("World")) ``` The above code defines a function that greets the user by name. ``` ~~~
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#1934